Install MySQL-5.7 in CentOs
Uninstallation process
Before installing mysql-5.7 in CentOs, you first need to check whether the system has mysql and mariadb installation packages. If so, you need to uninstall them cleanly.
First query mysql
rpm -qa | grep -i mysql
If the query is not empty, with other mysql services, you need to uninstall them all.
First query the existing mysql service running status, if it is running, stop it
service mysql status
service mysql stop
Then uninstall and delete the group key service installed by MySQL
userpm -evCommand to uninstall, for example:
rpm -ev mysql-community-libs-5.7.30-1.el7.x86_64
Normally, 4 services are installed, userpm -evJust uninstall one by one as in the above case.
If you encounter a dependency when uninstalling, you cannot uninstall. You can add at the end of the command- -nodeps, Which means that the dependencies between services are not checked when uninstalling.
Then check the files and folders corresponding to mysql
find / -name mysql
Use all the folders foundrm -rfCommands are all uninstalled cleanly one by one, for example:
rm -rf /etc/logrotate.d/mysql
After deleting, use againrpm -qa | grep -i mysqlCommand, if the result is empty, the uninstallation is successful
After that, you need to query mariadb, if there is, you need to uninstall
rpm -qa | grep mariadb 查询是否存在
rpm -e mariadb-libs-5.5.56-2.el7.x86_64(这里改成你查询出来的mariadb,复制粘贴过来即可) --nodeps 卸载
Use the query command to query again, if the query result is empty, the uninstallation is successful
Installation process
1. Determine the installation directory
cd /usr/tmp
mkdir mysql
2. Connect to the open source software mirror station of Tsinghua University , search for'mysql' in the search box, click to enter, click on'downloads/', and select the version MySQL-5.7 after entering, click on the count, ctrl+F, search for rpm, Click mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar to download.
I was directly in xshell6, after cd /usr/tmp, I directly entered the command to download directly
wget https://mirror.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
Use the tar command to decompress the downloaded file, the -C command is to decompress the file to the mysql folder in the current directory
tar xvf mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar -C ./mysql
after that
cd mysql
Enter the mysql folder
rpm -ivh mysql-community-common-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.30-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.30-1.el7.x86_64.rpm
Use the above command to install 4 rpm packages.
At this point, you can use the following command to start the mysql service
systemctl start mysqld
So it can be used
mysql -uroot -p
Log in to the mysql database, but no password is configured at this time, so the password needs to be found in the mysql log.
cat /var/log/mysqld.log | grep password
After
finding out, the string of code after the colon at the end is the password. Right-click to copy and use the mysql -uroot -p command above to log in, and paste the password you just copied to log in. It should be noted here that entering the password, whether it is manually entered or copied and pasted in, will not be displayed. This is a protection measure for linux.
Since the password in the log is not convenient for us to remember, we need to modify the login password. This version of mysql has improved password security requirements, and simple password settings cannot be successful. Therefore, you need to enter the configuration file first to lower the password security level of mysql. Use the following command
vim /etc/my.cnf
Enter the configuration file, press the i key to enter the insert mode, in the [mysqld] Enter the following code in the next line
validate_password=off
Press esc to exit insert mode, press: enter the last line mode, enter wq to save and exit,
then restart mysql
systemctl restart mysqld
Re-enter mysql, enter the password you just checked to enter
mysql -uroot -p
Then enter the command to modify the password
alter user 'root'@'localhost' identified by '你的密码';
After the modification is successful, enterexitCommand to exit mysql, and then usemysql -uroot -pCommand to enter mysql, enter the new password just set.
show databases;
Check the contents of the database. This is all done!
Thank you for watching!