文章目录
- 一、软件的选择与下载
- 二、卸载mysql8.0
- 1.查看my.cnf中的部署信息
- 2.卸载mysql8.0
- 3.卸载完毕安装包后删除相关数据
- 三、mysql5.7的安装
- 1.解压安装包
- 2.初始化mysql数据库
- 3.修改root密码
- 四、安装mysql5.7客户端
- 附:创建数据库以及用户
本次案例是卸载mysql8.0然后安装mysql5.7
因本次重装mysql数据库,所以不需要重新创建MySQL的用户以及my.cnf文件
一、软件的选择与下载
下载地址:https://dev.mysql.com/downloads/mysql/5.7.html
二、卸载mysql8.0
1.查看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.卸载mysql8.0
#停止mysql服务
[root@i-orwnzsqu mysql]# sudo service mysql stop
Shutting down MySQL.... SUCCESS!
[root@i-orwnzsqu mysql]#
#卸载mysql相关安装包
[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
略........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]#
#检查是否卸载干净
[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
#继续卸载:
[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.卸载完毕安装包后删除相关数据
删除红框中路径下的相关数据文件
至此卸载完成,重新安装mysql5.7
三、mysql5.7的安装
1.解压安装包
解压压缩包:mysql-5.7.42-linux-glibc2.12-x86_64.tar
解压压缩包:mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz
将解压后的目录移动重命名至/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.初始化mysql数据库
[root@i-orwnzsqu mysql]# cd bin/
[root@i-orwnzsqu bin]# ./mysqld --user=tdcxl --initialize --datadir=/data/mysql
[root@i-orwnzsqu bin]#
#初始化生成的root密码在log-error=/data/mysql/mysql.err中
#复制启动文件到/etc/init.d/目录
[root@i-orwnzsqu mysql]# cp -ar /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#启动mysql服务
[root@i-orwnzsqu mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
#添加开机自启
[root@i-orwnzsqu mysql]# chkconfig --add mysql
[root@i-orwnzsqu mysql]#
[root@i-orwnzsqu mysql]# chkconfig --listNote: This output shows SysV services only and does not include nativesystemd services. SysV configuration data might be overridden by nativesystemd 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]#
#查看默认生成的root密码
3.修改root密码
#添加环境变量方便登入
[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.42Copyright (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>
四、安装mysql5.7客户端
下载地址:https://downloads.mysql.com/archives/community/
如果安装过程中提示需要安装依赖包,可增加nodeps参数重新安装,如下:
[root@i-orwnzsqu mysql]# rpm -ivh --nodeps MySQL-client-5.7.31-1.el6.x86_64.rpm
附:创建数据库以及用户
mysql> create database tdcxltest;
Query OK, 1 row affected (0.00 sec)
#建用户:
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)
测试登录: