MariaDB is installed in CentOS by default. This is a branch of MySQL. However, MySQL should be installed in the system to meet the needs, and MariaDB can be directly overwritten after installation.
1 download and install the official Yum Repository of MySQL
[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
Use the above command to directly download the Yum Repository for installation, which is about 25KB, and then you can install it directly using 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, and the previous mariadb will be overwritten after the installation is completed.
At this point, MySQL installation is complete, and then some settings for MySQL.
2 MySQL database settings
Start MySQL first
[root@localhost ~]# systemctl start mysqld.service
View the running status of MySQL, as shown in the figure below:
[root@localhost ~]# systemctl status mysqld.service
At this time, MySQL is running normally. However, to enter mysql, you must first find 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
Enter the database with the following command:
[root@localhost ~]# mysql -uroot -p
Enter the initial password. Nothing can be done at this time, because MySQL must modify the password by default before operating the database:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
There is a problem here. If the new password is set too simply, an error will be reported:
The reason is that MySQL has a password setting specification, which is related to validate_ password_ The value of policy is related to:
The complete initial password rules of MySQL can be viewed through the following commands:
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 determines and validates_ password_ The calculation formula of length is:
validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
Mine has been modified. Initially, the first value is ON and validate_password_length is 8. You can modify it with the following command:
mysql> set global validate_password_policy=0; mysql> set global validate_password_length=1;
After setting, there are 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 complete.
However, there is another problem at this time. Because Yum Repository is installed, it will be updated automatically every time yum operation is performed in the future. You need to uninstall this:
[root@localhost ~]# yum -y remove mysql57-community-release-el7-10.noarch
It's really finished at this time.