1. Deactivate the service:
[root@iZ8vb8avlmvb451wmm14rqZ ~]# systemctl stop mysqld
Check if ps -ef|grep mysql is disabled
2. View and install mysql version
[root@iZ8vb8avlmvb451wmm14rqZ ~]# rpm -qa |grep -i mysql
mysql-common-8.0.26-1.1.al8.x86_64
mysql-server-8.0.26-1.1.al8.x86_64
mysql-8.0.26-1.1.al8.x86_64
mysql-community-release-el7-5.noarch
mysql-errmsg-8.0.26-1.1.al8.x86_64
3. Uninstall mysql
This method can uninstall all mysql8 at once, enter mysql and press the tab key to complete and then press Enter to uninstall
[root@iZ8vb8avlmvb451wmm14rqZ ~]# yum remove mysql-common.x86_64
In the middle, you will be asked to enter y to confirm. It is also possible to uninstall one by one. The name will be uninstalled if you write it word by word above.
View uninstall results
[root@iZ8vb8avlmvb451wmm14rqZ ~]# rpm -qa |grep -i mysql
mysql-community-release-el7-5.noarch
There are only 7 left. Uninstalled this too.
View the installable list under yum
[root@iZ8vb8avlmvb451wmm14rqZ ~]# yum repolist all|grep mysql
mysql-connectors-community MySQL Connectors Community enabled
mysql-connectors-community-source MySQL Connectors Community - Source disabled
mysql-tools-community MySQL Tools Community enabled
mysql-tools-community-source MySQL Tools Community - Source disabled
mysql55-community MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - Source disabled
mysql56-community MySQL 5.6 Community Server enabled
mysql56-community-source MySQL 5.6 Community Server - Source disabled
mysql57-community-dmr MySQL 5.7 Community Server Developmen disabled
mysql57-community-dmr-source MySQL 5.7 Community Server Developmen disabled
enabled means that it can be installed, select the version to be installed, for example, if you want to install 5.7, the code to kill 5.6 is as follows
yum-config-manager --disable mysql56-community
yum-config-manager --enable mysql57-community-dmr
After the installation was unsuccessful, it was uninstalled again until the result of the command yum repolist all|grep mysql was not empty
View the mysql directory: find / -name mysql
What is the output? Copy the path one by one, add rm -rf in front of the path, and delete all the paths directly
The search directory is as follows:
/var/lib/mysql /var/lib/mysql/mysql
Delete the corresponding mysql directory:
rm -rf /var/lib/mysql
rm -rf /var/log/mysqld.log
4. Install mysql 5.7
4.1. Download MySQL official Yum Repository (Mysql5.7)
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
4.2. Install Yum Repository
yum -y install mysql57-community-release-el7-10.noarch.rpm
View version information:
[root@iZ8vb8avlmvb451wmm14rqZ ~]# yum repolist all|grep mysql
We can see that there are 5.7 and 8.0, but we must disable the 8 version before executing the following command
4.3.Yum to install MySQL
yum install mysql-community-server --nogpgcheck --Bypass the verification or the installation will report an error
5. Start mysql
1. Start command systemctl start mysqld.service
2. Restart command systemctl restart mysqld.service
3. Close command systemctl stop mysqld.service
4. View status systemctl status mysqld.service
Another method is to enter the following command on the terminal command line to shut down the mysql service.
service mysqld stop #Close mmysql service
# or /etc/init.d/mysqld stop
service mysqld star #start mysql service
/etc/init.d/mysqld start #Start mysql service
Password login, view password command
grep 'temporary password' /var/log/mysqld.log
localhost: The following is the password. The first letter of my password is a space. It’s really fucked up. I have entered it more than ten times without success.
A temporary password is generated for root@localhost: :sgv)qZtQ3#b
Open mysqld.log directly with the tool and copy the password
6. Enter mysql
mysql -u root -p
7. Change password
【alter user 'root'@'localhost' identified by 'your new password'】
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
Refresh: FLUSH PRIVILEGES;
8. Open the remote connection
update user set host='%' where user='root';
Verify whether the modification is successful
select host,user from mysql.user;
Refresh: FLUSH PRIVILEGES;
create user
create user ‘username’@’%’ identified by ‘password’;
//Fill in your account name and password in username and password, % means remote connection is supported
Refresh: FLUSH PRIVILEGES;
9. Check whether it is currently a boot service
systemctl list-unit-files | grep mysql
If not, set it to boot
systemctl enable mysqld.service
The startup should be as follows
mysqld is the daemon process of mysql d is daemon
appendix:
Download the tar version of mysql5.7
Download from the official website
MySQL :: Download MySQL Community Server
This kind of installation is relatively complicated, it takes a long time to download files, and it is troublesome to configure. For details, please refer to