MariaDB is installed by default in CentOS, this is a branch of MySQL, but for needs, you still have to install MySQL in the system, and you can directly overwrite MariaDB after the installation is complete.
[ 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, about 25KB, and then you can directly install it with Yum.
[ root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
After that, install 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 complete.
At this point MySQL is installed, and then some settings for MySQL.
First start MySQL
[ root@localhost ~]# systemctl start mysqld.service
Check the running status of MySQL, as shown in the figure:
[ root@localhost ~]# systemctl status mysqld.service
At this point MySQL has started to run normally, but if you want to enter MySQL, you must first find out the password of the root user at this time. You can find the password in the log file by using 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, you can't do anything at this time, because MySQL must change the password to operate the database by default:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
There is a problem here. If the new password is set too simple, an error will be reported:
The reason is because MySQL has a password setting specification, which is specifically related to the value of validate_password_policy:
The complete initial password rules of MySQL can be viewed with 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 inset(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)
Mine has been modified. Initially, the first value is ON, and validate_password_length is 8. It can be modified by the following command:
mysql>set global validate_password_policy=0;
mysql>set global validate_password_length=1;
After setting, it is the values I found above. At this time, the password can be set very simple, such as 1234. The password setting of this database is complete.
But there is still a problem at this time, because Yum Repository is installed, and every yum operation will be automatically updated in the future, you need to uninstall this:
[ root@localhost ~]# yum -y remove mysql57-community-release-el7-10.noarch
Only then was it really finished.
Recommended Posts