MySQL is installed on Linux system (root login and online installation, provided that the system can access the Internet normally)

1. Configure YUM source

1.1 download mysql source installation package

[root@chris /]# wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

1.2 installing mysql source

[root@chris /]# yum localinstall mysql57-community-release-el7-11.noarch.rpm

1.3 check whether the mysql source is successfully installed

[root@chris /]# yum repolist enabled | grep mysql

You can change the mysql version installed by default with the following command.

[root@chris /]# vi /etc/yum.repos.d/mysql-community.repo

For example, to install version 5.6, change the enabled=1 of the 5.7 source to enabled=0. Then change the enabled=0 of the 5.6 source to enabled=1. The effect after the change is as follows:

2. Install MySQL

[root@chris /]# yum install mysql-community-server

All matches were filtered out by modular filtering for argument: MySQL community server
Error: Unable to find a match: mysql-community-server
Solution: first execute yum module disable mysql, and then execute Yum - y install MySQL community server

3. Start MySQL service

[root@chris /]# systemctl start mysqld

After successful startup, you can use the systemctl start mysqld command to view the startup status of MySQL

4. Set startup

[root@chris /]# systemctl enable mysqld

perhaps

[root@chris /]# chkconfig mysqld on

Note: for newly created unit files or modified unit files, notify systemd to reload this configuration file.

[root@chris /]# systemctl daemon-reload

5. Modify the root local login password

After mysql installation is completed, in / var / log / mysqld Log file generates a default password for root.
Use the following command to find the default root password, and then log in to mysql to modify it:

[root@chris /]# grep 'temporary password' /var/log/mysqld.log

Log in to mysql with the default password

[root@chris ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 108
Server version: 5.7.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Change Password

mysql> set password for 'root'@'localhost'=password('MyNewPassWord');

perhaps

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassWord';

Note: mysql5 7. The password security check plug-in (validate_password) is installed by default. The default password check policy requires that the password must contain upper and lower case letters, numbers and special symbols, and the length must not be less than 8 digits. Otherwise, error 1819 (HY000) will be prompted: your password does not satisfy the current policy requirements
After modifying the password, you can view the relevant information of the password policy through the msyql environment variable

mysql> show variables like '%password%';

validate_password_policy: password policy. The default is MEDIUM policy
validate_password_dictionary_file: password policy file, required only when the policy is STRONG
validate_password_length: minimum length of password
validate_password_mixed_case_count: length of upper and lower case characters, at least 1
validate_password_number_count: at least 1 number
validate_password_special_char_count: at least 1 special character

The above parameters are the password check rules of the default policy MEDIUM.
There are several password policies:

Policy check rules

0 or LOW Length 1 or MEDIUM Length; numeric, lowercase/uppercase, and
special characters 2 or STRONG Length; numeric, lowercase/uppercase,
and special characters; dictionary file

Detailed description of MySQL official website password policy
Modify password policy:
In / etc / my CNF file add validate_password_policy configuration, specify the password policy, select one of 0 (LOW), 1 (MEDIUM) and 2 (STRONG), and select 2 to provide the password dictionary file, validate_password_policy=0
If you do not need a password policy, add my Add the following configuration to CNF file and disable it:
validate_password = off
Restart the mysql service to make the configuration take effect
[root@chris /]# systemctl restart mysqld

6. Add remote login user

By default, only the root account is allowed to log in locally. If you want to connect to mysql on other machines, you must modify the root to allow remote connection. See the following blog for the modification method:
http://baijiahao.baidu.com/s?id=1666828886999436824&wfr=spider&for=pc
Or add an account that allows remote connections. For security reasons, here I add a new account:

mysql> GRANT ALL PRIVILEGES ON . TO 'linsili'@'%' IDENTIFIED BY 'linsili123' WITH GRANT OPTION; 1

7. Set the default code to utf8

Modify / etc / my CNF configuration file, add coding configuration under [mysqld], as shown below:
character_set_server=utf8
init_connect='SET NAMES utf8'

Restart the mysql service and check the default database code

mysql> show variables like '%character%';

The following is the path to the default configuration file:

Configuration file: / etc / my CNF log file: / var / log / / var / log / mysqld log
Service startup script: / usr / lib / SYSTEMd / system / mysqld service
socket file: / var / run / mysqld / mysqld pid

At this point, mysql installation is complete.

Keywords: Linux Database MySQL

Added by joeman3429 on Sat, 22 Jan 2022 01:18:28 +0200