How to install MySQL in CentOS7 through yum?
##1. Download and install MySQL’s official Yum Repository
[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
Copy after login
Use the above command to directly download Yum for installation. Repository, about 25KB, can be installed directly with yum.
[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
Copy after login
Then start installing the MySQL server.
[root@localhost ~]# yum -y install mysql-community-server
Copy after login
This step may take some time. After the installation is completed, the previous mariadb will be overwritten.
Now the MySQL installation is complete, and then there are some settings for MySQL.
2 MySQL database settings
First start MySQL
[root@localhost ~]# systemctl start mysqld.service
Copy after login
View the MySQL running status, the running status is as shown in the figure:
[root@localhost ~]# systemctl status mysqld.service
Copy after login
At this time, MySQL has started to run normally, but if you want to enter MySQL, you must first find out the password of the root user. You can find the password in the log file through the following command:
[root@localhost ~]# grep "password" /var/log/mysqld.log
Copy after login
The following command enters the database:
[root@localhost ~]# mysql -uroot -p
Copy after login
Enter the initial password. You cannot do anything at this time, because MySQL must change the password by default before operating the database:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
Copy after login
There is a problem here. When setting a new password, if the setting is too simple, an error will be reported:
The reason is because MySQL has password setting specifications, which are specifically related to the value of validate_password_policy:
The complete initial password rules of MySQL can be viewed through the following command:
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 4 |
| 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.01 sec)
Copy after login
The length of the password is determined by validate_password_length, and the calculation formula of validate_password_length is:
validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)我的是已经修改过的,初始情况下第一个的值是ON,validate_password_length是8。可以通过如下命令修改:
Copy after login
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
Copy after login
After setting, it will be the values I found above. At this time, the password can be set very simply, such as 1234. The password setting for this database is completed.
But there is another problem at this time, that is, because the Yum Repository is installed, every yum operation will be automatically updated in the future, and this needs to be uninstalled:
[root@localhost ~]# yum -y remove mysql57-community-release-el7-10.noarch
Copy after login
Related references:
centOS tutorial
At this time, it is really completed.
The above is the detailed content of How to install MySQL through yum in CentOS7. For more information, please follow other related articles on the PHP Chinese website!