Uninstall and reinstall mysql5.7 based on redhat release version mysql8.0

Article directory

  • 1. Software selection and download
  • 2. Uninstall mysql8.0
    • 1. View the deployment information in my.cnf
    • 2. Uninstall mysql8.0
    • 3. Delete relevant data after uninstalling the installation package
  • 3. Installation of mysql5.7
    • 1. Unzip the installation package
    • 2. Initialize the mysql database
    • 3. Modify the root password
  • Fourth, install the mysql5.7 client
  • Attachment: create database and user

This case is to uninstall mysql8.0 and then install mysql5.7
Because the mysql database is reinstalled this time, there is no need to recreate the MySQL user and my.cnf file

1. Software selection and download

Download address: https://dev.mysql.com/downloads/mysql/5.7.html

2. Uninstall mysql8.0

1. Check the deployment information in my.cnf

[root@i-orwnzsqu etc]# cat my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=zysjswjw
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
#socket=/var/lib/mysql/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8MB4
symbolic-links=0
explicit_defaults_for_timestamp=true


[client]
socket=/tmp/mysql.sock
default-character-set=utf8
[root@i-orwnzsqu etc]#

2. Uninstall mysql8.0

#stop mysql service
[root@i-orwnzsqu mysql]# sudo service mysql stop
Shutting down MySQL....SUCCESS!
[root@i-orwnzsqu mysql]#
#Uninstall mysql related installation packages
[root@i-orwnzsqu mysql]# sudo yum remove mysql mysql-server mysql-libs mysql-devel mysql-client
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-client.x86_64 0:8.0.32-1.el7 will be erased
---> Package mysql-community-libs.x86_64 0:8.0.32-1.el7 will be erased
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-libs-compat-5.7.13-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.13-1.el7 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: php56w-mysql-5.6.23-1.w7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: zabbix-proxy-mysql-3.0.3-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: zabbix-server-mysql-3.0.3-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: php56w-mysql-5.6.23-1.w7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: zabbix-proxy-mysql-3.0.3-1.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: zabbix-server-mysql-3.0.3-1.el7.x86_64
--> Running transaction check
---> Package php56w-mysql.x86_64 0:5.6.23-1.w7 will be erased
--> Processing Dependency: php-mysql for package: zabbix-web-mysql-3.0.3-1.el7.noarch
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
---> Package zabbix-proxy-mysql.x86_64 0:3.0.3-1.el7 will be erased
---> Package zabbix-server-mysql.x86_64 0:3.0.3-1.el7 will be erased
--> Running transaction check
---> Package zabbix-web-mysql.noarch 0:3.0.3-1.el7 will be erased
--> Processing Dependency: zabbix-web-database = 3.0.3-1.el7 for package: zabbix-web-3.0.3-1.el7.noarch
--> Running transaction check
---> Package zabbix-web.noarch 0:3.0.3-1.el7 will be erased
--> Finished Dependency Resolution
slightly........

Complete!
[root@i-orwnzsqu mysql]#
[root@i-orwnzsqu mysql]# sudo yum autoremove
Loaded plugins: fastestmirror
No Packages marked for removal
[root@i-orwnzsqu mysql]#
[root@i-orwnzsqu mysql]# sudo yum clean all
Loaded plugins: fastestmirror
Cleaning repos: softinstll
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@i-orwnzsqu mysql]#
#Check if uninstall is clean
[root@i-orwnzsqu zysjswjw]# rpm -qa | grep mysql
mysql-community-client-plugins-8.0.32-1.el7.x86_64
mysql-community-common-8.0.32-1.el7.x86_64
mysql57-community-release-el7-8.noarch
#Continue to uninstall:
[root@i-orwnzsqu zysjswjw]# sudo yum remove mysql mysql-common
[root@i-orwnzsqu zysjswjw]# sudo yum remove mysql mysql-community-client-plugins-8.0.32-1.el7.x86_64
[root@i-orwnzsqu zysjswjw]# yum remove mysql mysql57-community-release-el7-8.noarch
[root@i-orwnzsqu zysjswjw]# rpm -qa | grep mysql
[root@i-orwnzsqu zysjswjw]#

3. Delete relevant data after uninstalling the installation package

Delete the relevant data files under the path in the red box

So far the uninstallation is complete, reinstall mysql5.7

3. mysql5.7 installation

1. Unzip the installation package

Decompress the compressed package: mysql-5.7.42-linux-glibc2.12-x86_64.tar

Decompress the compressed package: mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz

Move and rename the decompressed directory to /usr/local/mysql

[root@i-orwnzsqu local]# mv /home/tdcxl/mysql-5.7.42-linux-glibc2.12-x86_64 /usr/local/mysql
[root@i-orwnzsqu local]# cd /usr/local/mysql/
[root@i-orwnzsqu mysql]# ll
total 284
drwxrwxr-x 2 tdcxl tdcxl 4096 Jul 3 12:00 bin
drwxrwxr-x 2 tdcxl tdcxl 4096 Jul 3 12:00 docs
drwxrwxr-x 3 tdcxl tdcxl 4096 Jul 3 12:00 include
drwxrwxr-x 5 tdcxl tdcxl 4096 Jul 3 12:00 lib
-rw-r--r-- 1 tdcxl tdcxl 255738 Mar 16 23:25 LICENSE
drwxrwxr-x 4 tdcxl tdcxl 4096 Jul 3 12:00 man
-rw-r--r-- 1 tdcxl tdcxl 566 Mar 16 23:25 README
drwxrwxr-x 28 tdcxl tdcxl 4096 Jul 3 12:00 share
drwxrwxr-x 2 tdcxl tdcxl 4096 Jul 3 12:00 support-files

2. Initialize the mysql database

[root@i-orwnzsqu mysql]# cd bin/
[root@i-orwnzsqu bin]# ./mysqld --user=tdcxl --initialize --datadir=/data/mysql
[root@i-orwnzsqu bin]#
#The root password generated by initialization is in log-error=/data/mysql/mysql.err
#Copy the startup file to the /etc/init.d/ directory
[root@i-orwnzsqu mysql]# cp -ar /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#Start the mysql service
[root@i-orwnzsqu mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
#Add autostart
[root@i-orwnzsqu mysql]# chkconfig --add mysql
[root@i-orwnzsqu mysql]#
[root@i-orwnzsqu mysql]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

jexec 0:off 1:on 2:on 3:on 4:on 5:on 6:off
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@i-orwnzsqu mysql]#

#View the root password generated by default

3. Modify the root password

#Add environment variables to facilitate login
[root@i-orwnzsqu mysql]# mysql -uroot -p
-bash: mysql: command not found
[root@i-orwnzsqu mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@i-orwnzsqu mysql]# source /etc/profile
[root@i-orwnzsqu mysql]#
[root@i-orwnzsqu mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.42

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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>
mysql> set password for root@localhost = password('12345678');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>

4. Install mysql5.7 client

Download address: https://downloads.mysql.com/archives/community/

If you are prompted to install dependent packages during the installation process, you can increase the nodeps parameter to reinstall, as follows:
[root@i-orwnzsqu mysql]# rpm -ivh --nodeps MySQL-client-5.7.31-1.el6.x86_64.rpm

Attachment: Create database and user

mysql> create database tdcxltest;
Query OK, 1 row affected (0.00 sec)
#Build user:
mysql> create user 'tdcxltest'@'%' identified by 'tdcxltest';
Query OK, 0 rows affected (0.02 sec)

mysql> grant all privileges on tdcxltest.* to tdcxltest@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Test login: