Installation and configuration of mysql5.7 under 64 bit centos7


Installation environment: centos7 64 bit mini, install MySQL 5.7

1. Configure Yum source

Download the yum source RPM installation package from the MySQL official website:

#Download MySQL source installation package
shell> wget
#Install MySQL source
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm

Check whether the MySQL source is installed successfully

shell> yum repolist enabled | grep "mysql.*-community.*"

See the figure above to indicate successful installation.

You can modify the yum source to change the default version of MySQL. For example, to install version 5.7, change the enabled = 0 of the 5.7 source to enabled = 1. The results are as follows:

vim /etc/yum.repos.d/mysql-community.repo

2. Install MySQL

shell> yum install mysql-community-server

3. Start MySQL service

shell> systemctl start mysqld

View the startup status of MySQL

4. Boot up

shell> systemctl enable mysqld
shell> systemctl daemon-reload

5. Modify the local login password of root. It is possible that the default password of root is empty

1. If the default password is empty, directly enter to log in

If there is a password, after the MySQL installation is completed, in / var / log/ mysqld.log A default password is generated for root in the file. Find the root default password in the following way, and then log in to MYSQL to modify it:

shell> grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');

Note: mysql5.7 installs the validate plug-in by default_ The default password checking policy requires that the password must contain upper and lower case letters, numbers and special symbols, and the length must not be less than 8 digits. Otherwise, it will prompt error 1819 (HY000): your password does not satisfy the current policy requirements, as shown in the figure below:

The MSYQL environment variable can be used to view the password policy information

mysql> show variables like '%password%';

validate_ password_ Policy: password policy. The default is medium policy
validate_ password_ dictionary_ File: password policy file, which is required only when the policy is strong
validate_ password_ Length: minimum password length
validate_ password_ mixed_ case_ Count: length of upper and lower case characters, at least 1
validate_ password_ number_ Count: at least one number
validate_ password_ special_ char_ Count: at least one special character

The above parameters are password checking rules for the default policy medium.

There are several password policies:

MySQL official website password policy details: validate_ password_ policy

Modify password policy

In / etc/ my.cnf File add validate_ password_ Policy configuration to specify the password policy

#Select one of 0 (low), 1 (medium), 2 (strong), and select 2 to provide password dictionary file

If no password policy is required, add my.cnf Add the following configuration to the file and disable it:

validate_password = off

Restart the MySQL service to make the configuration take effect:

systemctl restart mysqld

6. Add remote login user

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


7. The default encoding is utf8

Modify / etc/ my.cnf In the configuration file, add the coding configuration under [mysqld], as follows:

init_connect='SET NAMES utf8'

Restart the MySQL service and check the database default code as follows:

Default profile path:
Configuration file / etc/ my.cnf
Log file / var / log / / var / log/ mysqld.log
Service startup script / usr / lib / SYSTEMd / system/ mysqld.service
Socket file / var / run / mysqld/

Centos7 uninstall MySQL

View current installation status

rpm -qa|grep -i mysql

yum remove mysql

rpm -e mysql-community-release-el7-5.noarch

If dependency error is prompted

Then execute

rpm -ev --nodeps mysql-community-libs-5.6.43-2.el7.x86_64

Delete in this way

Then I look up the directory of the old version of MySQL and delete the files and libraries of the old version of MySQL. Instead of deleting the old library, I do an upgrade and installation directly

find / -name mysql

Delete the corresponding MySQL directory

rm -rf /var/lib/mysql

Note: after unloading / etc/ my.cnf It will not be deleted and needs to be manually deleted

rm -rf /etc/my.cnf

my.cnf Sometimes it’s not necessarily in / etc, you can use the command to find

find / -name my.cnf

Find out whether MySQL is installed on the machine again

rpm -qa|grep -i mysql

I did not delete the original configuration file, database, directly installed 5.7, the original data inventory, but the database can not be used, I used two commands to solve the problem.

set @@global.show_compatibility_56=ON;

The original database can be used normally.


The above is the installation and configuration tutorial of mysql5.7 under 64 bit centos7 introduced by Xiaobian. I hope it can help you. If you have any questions, please leave me a message and Xiaobian will reply you in time. Thank you very much for your support to developer!
If you think this article is helpful to you, please reprint, please indicate the source, thank you!

Recommended Today

SQL exercise 20 – Modeling & Reporting

This blog is used to review and sort out the common topic modeling architecture, analysis oriented architecture and integration topic reports in data warehouse. I have uploaded these reports to GitHub. If you are interested, you can have a lookAddress: recorded a relatively complete development process in my hexo blog deployed on GitHub. You can […]