Home>Article>Operation and Maintenance> How to install MySQL through yum in CentOS7

How to install MySQL through yum in CentOS7

WJ
WJ Original
2020-06-02 16:27:36 2058browse

How to install MySQL through yum in CentOS7

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

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

Then start installing the MySQL server.

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

This step may take some time. After the installation is completed, the previous mariadb will be overwritten.

How to install MySQL through yum in CentOS7

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

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

How to install MySQL through yum in CentOS7

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

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

How to install MySQL through yum in CentOS7

The following command enters the database:

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

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';

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:

How to install MySQL through yum in CentOS7

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)

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。可以通过如下命令修改:
mysql> set global validate_password_policy=0; mysql> set global validate_password_length=1;

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

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn