Install MySQL-5.7 on CentOS7
At that time, the installation of mysql5.7 encountered many problems, online solutions are not right, record down their own installation of successful installation steps and notes
Install mysql 5.7
Update yum local cache
1
2
|
yum clean cache
yum makecache
|
Check if mysql is installed on the system
1
|
yum list installed | grep mysql
|
Uninstall mysql and its dependencies that come with the system (to prevent conflicts)
1
|
yum -y remove mysql-libs.x86_64
|
Install wget
Add rpm sources to centos and select the newer ones
1
|
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
|

Install the downloaded rpm file

Go to the directory /etc/yum.repos.d/ and these two files will be added

1
|
vi mysql-community.repo
|

Install mysql using yum
1
|
yum install mysql-community-server -y
|


Check the version of mysql to make sure it’s installed successfully

Start mysql service

Set mysql to start on boot
From the mysqld.log file, view the mysql temporary password
1
|
grep "password" /var/log/mysqld.log
|

Copy the temporary password above and login to mysql
1
|
mysql -uroot -p[Temporary password]
|
- If there are special characters in the temporary password, you need to add \\ escape, otherwise it will prompt the character exception
- Do not have spaces after -u and -p, or you will be prompted with a password error
Change the password authentication policy (do not change it, the modified password may not pass), and then change the root user password
1
2
3
|
set global validate_password_policy=0;
set global validate_password_length=4;
alter user 'root'@'localhost' identified by '123456';
|

- After successfully changing your password, type quit to log out, and then log back in with your new password.
Set the database user to be accessible under all ip’s, the following example with the root user (enter this command in mysql)
1
|
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
|

- where root is the user, % indicates all privileges, and the password is 123456

Use quit or exit to quit mysql and restart mysql service
Turn on the firewall
The linux firewall is not opened on port 3306 by default, you need to open it manually so that the local client can connect to the mysql service on linux.
Check if port 3306 is open
1
|
firewall-cmd --query-port=3306/tcp
|

- yes, means on; no means not on
On the firewall, add the port 3306 that needs to be opened
1
|
firewall-cmd --add-port=3306/tcp --permanent
|

Reload the added port

Query again whether port 3306 is open, and confirm that it is open
1
|
firewall-cmd --query-port=3306/tcp
|

Uninstall mysql on linux
If the installation fails and you want to reinstall it, you need to remove all mysql related ones.
Check the installed mysql components
1
|
rpm -qa | grep -i mysql
|

Delete the queried files one by one
1
2
3
|
yum remove mysql-community-libs-compat-5.7.35-1.el7.x86_64
yum remove mysql-community-release-el6-5.noarch
yum remove mysql-community-common-5.7.35-1.el7.x86_64
|


1
2
3
4
5
6
|
yum remove mysql mysql-server mysql-libs mysql-server
rm -rf /var/lib/mysq
rm /etc/my.cnf
rm –rf /usr/lib64/mysql
rm -rf /etc/yum.repos.d/mysql*
rm -rf mysql-community-release-el6-5.noarch.rpm
|
Find residual directories, then use the rm command to delete them one by one