I started with version 5.7, now I’m going to reinstall and change to a higher version (MySQL8.0.20).
1, the first step, clean up the environment
- First, check to see if the mysql database is installed on your system
rpm -qa | grep mysql
Copy the code
[root @ localhost etc] # RPM - qa | grep mysql mysql - community - libs - 8.0.16-2. El7. X86_64 Mysql - community - common - 8.0.16-2. El7. X86_64 mysql - community - the client - 8.0.16-2. El7. X86_64 Mysql80 - community - release - el7-3. Noarch mysql - community - server - 8.0.16-2. El7. X86_64Copy the code
- After you query the installed MySQL library, run the following commands to uninstall it
yum remove mysql-xxx-xxx
Copy the code
If the Mysql database is not installed, skip this step.
- Delete the mysql configuration file. The mysql uninstallation does not automatically delete the configuration file. You need to delete the configuration file by yourself.
First, run the following command to find the configuration file used
find / -name mysql
Copy the code
[root@localhost etc]# find / -name mysql
/etc/logrotate.d/mysql
/var/lib/docker/overlay2/a74267a6cde69551beede82788b48f1430f6ac88e4c7a8cdf9bcf16b2125aac6/diff/etc/mysql
/var/lib/docker/overlay2/a74267a6cde69551beede82788b48f1430f6ac88e4c7a8cdf9bcf16b2125aac6/diff/usr/include/mysql
/var/lib/docker/overlay2/a74267a6cde69551beede82788b48f1430f6ac88e4c7a8cdf9bcf16b2125aac6/diff/usr/include/mysql/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
Copy the code
Run the following commands to delete configuration files as required
rm -rf /var/lib/mysql
Copy the code
Delete MariaDB files
MariaDB is installed in CentOS by default, so if we do not delete MariaDB file, mysql installation may cause conflicts. 1. Run the RPM command to find the mariadb file to be deleted
rpm -pa | grep mariadb
Copy the code
Possible results
Mariadb - libs - 5.5.56-2. El7. X86_64Copy the code
Delete the above program
yum -y remove mariadb-libs.x86_64
Copy the code
At this point, the original mysql and Mariadb databases are deleted
Install mysql
- Address: dev.mysql.com/downloads/r…
- # yum install wget # yum install wget # yum install wget Using the command
Wget HTTP: / / http://dev.mysql.com/get/Downloads/mysql80-community-release-el7-1.noarch.rpmCopy the code
- Install mysql80-community-release-el7-1.noarch. RPM package. Use the following command:
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
Copy the code
- Run the yum install mysql-community-server command to install mysql. Please wait patiently for the installation to complete
yum install mysql-community-serve
Copy the code
The default configuration file path: the configuration file: / etc/my CNF log file: / var/log/var/log/mysqld log service startup scripts: / usr/lib/systemd/system/mysqld. Service socket file: /var/run/mysqld/mysqld.pid
4. Initialize mysql
Start the mysqld service and set it to start automatically upon startup. Command: // this is the command of centos7
systemctl start mysqld.service
systemctl enable mysqld.service
Copy the code
5. Change the initial password
1. Edit the MyQL configuration file and add the following information
[root@localhost etc]# vim /etc/my.cnf
Copy the code
Add the following
Default-authentication-plugin =mysql_native_password # symbolic-links=0 skip-grant-tablesCopy the code
Save the Settings and exit.
- Restarting the MySQL service
systemctl restart mysqld
Copy the code
3. Log in to the MySQL database without a password
mysql -u root -p
Copy the code
The demo is as follows:
[root@localhost etc]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 8.0.16 MySQL Community Server - GPL Copyright (C) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help; ' or '\h' for help. Type '\c' to clear the current input statement. mysql>Copy the code
Enter password: Press Enter
- On the Mysql page, perform the following operations
(1) Set the old password to empty
flush privileges;
Copy the code
use mysql;
Copy the code
Update user set authentication_string= ' 'where user=' root ';Copy the code
(2) Set the root password to Haha@123. Note that the password setting rule of Mysql8 must be upper and lower case letters, special characters, and digits
Alter user 'root' @ 'localhost' identified by 'Haha@123';Copy the code
(3) Change host % to facilitate remote access
Update user set host = '%' where user= 'root';Copy the code
(4) Use the password already set to change the encryption mode
ALTER USER 'root' @ '%' IDENTIFIED BY 'Haha@123' PASSWORD EXPIRE NEVER;Copy the code
(5) Use the new encryption method to reset the password
ALTER USER 'root' @ '%' IDENTIFIED WITH mysql_native_password BY 'Haha@5678;Copy the code
The refresh
flush privileges;
Copy the code
Restarting the MySQL service
systemctl restart mysqld
Copy the code
Note: At the beginning, I encountered a problem that I could connect to MySQL Server without entering a password or entering a wrong password. Later, when I changed the password to allow alicentos7 to allow remote operation of MySQL database,
CNF file, comment out skip-grant-tables, restart MySQL service (sudo service mysqld restart), quit connection, re-connection will need to enter the password, if you forget the password later. If ‘root’@’ localhost’ is changed to ‘root’@’%’, then the alter statement must be changed as well