centos7 yum install mysql5.7

By default, MariaDB is installed in CentOS, which is a branch of MySQL. However, in order to meet the needs, MySQL should be installed in the system, and MariaDB can be directly overwritten after the installation.

1 download and install MySQL's official Yum Repository

[root@centos7 ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

Use the above command to download the Yum Repository for installation, about 25KB, and then install it directly.

[root@centos7 ~]# yum -y install mysql80-community-release-el7-3.noarch.rpm

Modify to the required version, disable the version not required by mysql in the yum repository and enable the required version

yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
 Manually edit the file / etc/yum.repos.d/mysql-community.repo to select, change the enabled=1 of the default version to 0, and the enabled=1 of the version is required

View the mysql version in the yum repository. It defaults to the latest enabled version and needs to be changed to the required version

yum repolist all | grep mysql

After that, install the MySQL server.

[root@centos7 ~]# yum -y install mysql-community-server

This step may take some time, and the previous mariadb will be overwritten after installation.

At this point, MySQL installation is complete, and then some settings for MySQL.

2 MySQL database settings

Start MySQL first

[root@centos7 ~]# systemctl start  mysqld.service

View the running status of MySQL, as shown in the figure:

[root@centos7 ~]# systemctl status mysqld.service

At this time, MySQL is running normally. However, to enter mysql, you must find the password of the root user. You can find the password in the log file by the following command:

[root@centos7 ~]# grep "temporary password" /var/log/mysqld.log

Note: if this file is empty:

1.Remove the previously installed mysql Residual data (this step is very important, and the problem is here)
rm -rf /var/lib/mysql
2.restart mysqld service
systemctl restart mysqld
3.Find the temporary password again
grep 'temporary password' /var/log/mysqld.log  

Enter the database as follows:

[root@centos7 ~]# mysql -uroot -p

Enter the initial password, and nothing can be done at this time, because MySQL must modify the password by default to operate the database:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

There is a problem here. When setting a new password, if it is too simple, an error will be reported:

The reason is that MySQL has a password setting specification, which is specifically related to the value of validate ﹣ password ﹣ policy


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 total number of upper / lower case letters in the whole password;
4) , validate ﹣ password ﹣ number ﹣ count the number of Arabic numerals in the whole password;
5) , validate ﹣ password ﹣ policy specifies the strength authentication level of the password, which is MEDIUM by default;
    About the value of validate ﹣ password ﹣ policy:
    0 or LOW: only the length is verified;
    1 or MEDIUM: verification length, number, case, special character;
    2 or STRONG: verify length, number, case, special character, dictionary file;
6) , validate ﹣ password ﹣ special ﹣ char ﹣ count the number of special characters in the whole password;

The complete initial password rules of MySQL can be viewed by the following command:

mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=8;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password%';
| Variable_name                        | Value |
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 8     |
| validate_password_mixed_case_count   | 1     |
| validate_password_number_count       | 1     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
7 rows in set (0.00 sec)



By default, only root account is allowed to log in locally. If you want to connect mysql on other machines, you must modify root to allow remote connection


After setting, I find out the values above. At this time, the password can be set very simply, such as 1234 and so on. The password settings for this database are complete.

Configure database encoding

vim /etc/my.cnf



But there is another problem at this time, because Yum Repository is installed, and every yum operation will update automatically in the future. You need to uninstall this:

[root@localhost ~]# yum -y remove mysql80-community-release-el7-3.noarch

That's when it's really done.

Published 6 original articles, won praise 12, visited 10000+
Private letter follow

Tags: MySQL yum Database MariaDB

Posted on Wed, 05 Feb 2020 04:45:41 -0800 by emopoops