Install mysql5.7 under CentOS7

**

1. Install YUM Repo

**
1. Since there is no mysql in the yum source of CentOS, you need to download the yum repo configuration file from the official website of mysql.
Download command:

wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

2. Then install the repo:

rpm -ivh mysql57-community-release-el7-9.noarch.rpm

After the execution is completed, two repo files mysql-community.repo mysql-community-source.repo will be generated in the /etc/yum.repos.d/ directory

2. Use the yum command to complete the installation

Note: You must enter the /etc/yum.repos.d/ directory before executing the following script

1. Installation command:

yum install mysql-server --nogpgcheck

2. Start msyql:

systemctl start mysqld

3. Obtain the temporary password during installation (use this password when logging in for the first time):

grep 'temporary password' /var/log/mysqld.log

Three, login:

1. Method 1 (verified):

mysql -u root -p

Then enter the password (the temporary password just obtained)

2. Method 2 (unverified):
Enter the mysql database

root@test:/home# mysql -uroot -proot

3. If you cannot log in, perform the following configuration and skip the login verification
3.1. The first step to reset the password is to skip the MySQL password authentication process. The method is as follows:

vim /etc/my.cnf

(Note: My.ini is modified under windows)
Searching for mysqld within the documentation locates the [mysqld] text segment:
/mysqld (directly enter this command in the vim editing state to search for text content)
Add “skip-grant-tables” to any line after [mysqld] to skip the password verification process, as shown in the following figure:
insert image description here
3.2. Save the document and exit:

:wq

3.3. Next, we need to restart MySQL:

4. Change password after successful login

1. Note: Password strength verification will be performed here (the password must contain uppercase and lowercase letters, special symbols, numbers, and the length is greater than 8 digits)
2. If the above conditions are not met, an error will be reported, as shown in the figure below:
Password policy problem exception information: ERROR 1819 (HY000): Your password does not satisfy the
current policy requirements
insert image description here

3. Solution:
3.1. View the initial password policy of mysql,

SHOW VARIABLES LIKE 'validate_password%

Enter the statement ” SHOW VARIABLES LIKE ‘validate_password%’; ” to view,
As shown below:
insert image description here

3.2. First, you need to set the verification strength level of the password, and set the global parameter of validate_password_policy to LOW.

 set global validate_password_policy=LOW;

Enter the setting statement “set global validate_password_policy=LOW;” to set the value,

3.3. The current password length is 8. If you don’t mind, you don’t need to modify it. Generally speaking, set it to a 6-digit password, and set the global parameter of validate_password_length to 6.

set global validate_password_length=6;

Enter the setting statement “set global validate_password_length=6;” to set the value,

3.4. Now you can set a simple password for mysql, as long as it meets the length of six digits,

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

Enter the modification statement ” ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘123456’; ” You can see that the modification is successful, indicating that the password policy modification is successful! ! !

3.5. Note: The minimum length of the default password is 4, consisting of one uppercase/lowercase letter + one Arabic numeral + one special character,
As long as the length of the set password is less than 3, it will be automatically set to 4,

3.6. About mysql password policy related parameters;
1), validate_password_length The total length of the fixed password;

2), validate_password_dictionary_file specifies the file path for password verification;

3), validate_password_mixed_case_count The entire password must contain at least the total number of uppercase/lowercase letters;

4), validate_password_number_count The entire password must contain at least the number of Arabic numerals;

5), validate_password_policy specifies the strength verification level of the password, and the default is MEDIUM;

Regarding the value of validate_password_policy:

LOW: Only verify the length;

1/MEDIUM: Verify length, numbers, case, special characters;

2/STRONG: Verify length, number, case, special characters, dictionary file;

6), validate_password_special_char_count The entire password must contain at least the number of special characters;

5. Change password

1. Method 1 (verified):

ALTER USER 'root'@'localhost' IDENTIFIED BY '@abcd123456';

2. Method 2 (unverified)

set password=password("yourpassword");

6. Enable remote control

MySQL does not enable remote control by default, and you must add a remote access user, that is, you can only access it by yourself by default, and other machines cannot access it.

1. Method 1 (verified):
1.1. Connect to the server:

mysql -u root -p

1.2. View all current databases:

show databases;

1.3. Enter the mysql database:

use mysql;

1.4. View all tables in the mysql database:

show tables;

1.5. View the data in the user table:

select Host, User, Password from user;

1.6. Modify the Host in the user table:

update user set Host='%' where User='root';

Note: % stands for any client and can be replaced with a specific IP address.
1.7. Finally refresh:

flush privileges;

1.8. Note: You must remember to add ” ; ” after the statement is completed when writing sql

2. Method 2 (unverified):
1. Use the grant command

grant all privileges on database name. table name to created user name (root)@“%” identified by “password”;
2. Format description:
Database name. Table name If it is written as *.*, it means that all databases are authorized flush privileges; #Refresh the content just now

like:

grant all privileges on . to root@“113.123.123.1” identified by “123456789”;

@ is followed by the IP address (or host name) of the client accessing mysql % represents any client, if you fill in localhost for local access (then this user cannot remotely access the mysql database)

7. Other configuration

1. Set security options:

mysql_secure_installation

2. Close MySQL

systemctl stop mysqld

3. Restart MySQL

systemctl restart mysqld

4. View the running status of MySQL

systemctl status mysqld

5. Set the boot to start

systemctl enable mysqld

6. Turn off the boot

systemctl disable mysqld

7. Configure the default encoding as utf8:
vi /etc/my.cnf #Add [mysqld] character_set_server=utf8 init_connect=’SET NAMES utf8′

Other default configuration file paths:

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

8. View version

select version();

Reference: https://blog.csdn.net/wohiusdashi/article/details/89358071