MySQL 小版本升级

MySQL 版本升级(in-place upgrade 小版本升级 5.7.33 -> 5.7.37)

下载 mysql 5.7.37 版本

1
[root@s00ythmysql02 local]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

备份数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@s00ythmysql02 local]# sudo /data/mysql/script/backup.sh

mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
----------------------------

./backup.sh: MySQL备份脚本
开始于: 2022-02-09 14:30:07 3

*********************************
正在执行全新的完全备份...请稍等...
*********************************
数据库成功备份到:/data/mysql/backup/xtrabackup/full/2022-02-09_14-30-07/
必须保留1份全备和全备2022-02-09_14-30-07以后的所有增量备份.
rm: refusing to remove "." or ".." directory: skipping "."

未找到可以删除的过期全备文件

完成于: 2022-02-09 15:19:17 3

版本升级

3.1 设置参数 innodb_fast_shutdown 为 0。

注:innodb_fast_shutdown有0、1、2三个值。
参数值为0代表MySQL关闭,InnoDB需要完成所有的full purge和merge Insert buffer操作,这个过程需要一定的时间,有时可能会花上几个小时。
参数值为1是该参数的默认值,表示关闭MySQL时不完成full purge和Merge insert buffe操作,但是缓冲池中的脏页还是会写到磁盘中。
参数值为2时,表示既不完成full purge和Merge insert buffer操作,也不将缓冲池中的脏页刷新到磁盘,而是将日志写入日志文件中。

1
2
3
4
5
6
7
8
mysql(root@10.81.106.93)>set global innodb_fast_shutdown=0;
mysql(root@10.81.106.93)>select @@innodb_fast_shutdown;
+------------------------+
| @@innodb_fast_shutdown |
+------------------------+
| 0 |
+------------------------+
1 row in set (0.00 sec)

3.2 关闭 mysql 服务

1
[root@s00ythmysql02 local]# systemctl stop mysql

3.3 解压 5.7.37 软件包

1
[root@s00ythmysql02 local]# tar -zxvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

3.4 更改软链接地址

1
2
3
[root@s00ythmysql02 local]# mv mysql-5.7.37-linux-glibc2.12-x86_64 mysql-5.7.37
[root@s00ythmysql02 bin]# ln -snf /usr/local/mysql-5.7.37/bin/mysql /bin/mysql
[root@s00ythmysql02 bin]# ln -snf /usr/local/mysql-5.7.37/bin/mysqladmin /bin/mysqladmin

3.5 更改 /etc/my.cnf

​ basedir = /usr/local/mysql-5.7.37

3.6 启动 mysql 实例

注:在启动过程中,需要添加 –skip-grant-tables–skip-networking 参数,来保证没有任何的应用连接,让升级过程更加安全。

1
[root@s00ythmysql02 bin]# /usr/local/mysql-5.7.37/bin/mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables --skip-networking &

3.7 升级系统表数据字典信息

1
[root@s00ythmysql02 bin]# /usr/local/mysql-5.7.37/bin/mysql_upgrade -uroot -p

3.8 升级成功重启 mysql 服务

1
[root@s00ythmysql02 bin]# /usr/local/mysql-5.7.37/bin/mysqladmin -uroot -p shutdown

更新 mysql 自启动配置

更新 mysql.service 文件

1
[root@s00ythmysql02 bin]# vi /usr/lib/systemd/system/mysql.service

​ ExecStart=/usr/local/mysql-5.7.37/bin/mysqld_safe –defaults-file=/etc/my.cnf –user=mysql

1
2
[root@s00ythmysql02 bin]# systemctl daemon-reload
[root@s00ythmysql02 bin]# systemctl start mysql