MySQL主从架构小版本升级

从库

一、新版本mysql环境准备

1.解压mysql 5.7.31

tar -zxf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /software/

2. 替换软链接

[root@study04 software]# ll
total 0
drwxr-xr-x 3 mysql mysql 209 Apr 12 14:14 3307
drwxr-xr-x 3 mysql mysql 209 Apr 12 14:22 3308
lrwxrwxrwx 1 mysql mysql  35 Apr 12 11:36 mysql -> mysql-5.7.25-linux-glibc2.12-x86_64
drwxr-xr-x 9 mysql mysql 129 Apr 12 11:30 mysql-5.7.25-linux-glibc2.12-x86_64
drwxr-xr-x 9  7161 31415 129 Jun  2  2020 mysql-5.7.31-linux-glibc2.12-x86_64

[root@study04 software]# unlink mysql

[root@study04 software]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64 mysql

[root@study04 software]# ll
total 0
drwxr-xr-x 3 mysql mysql 209 Apr 12 14:14 3307
drwxr-xr-x 3 mysql mysql 209 Apr 12 14:22 3308
lrwxrwxrwx 1 root  root   35 Apr 12 14:28 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64
drwxr-xr-x 9 mysql mysql 129 Apr 12 11:30 mysql-5.7.25-linux-glibc2.12-x86_64
drwxr-xr-x 9  7161 31415 129 Jun  2  2020 mysql-5.7.31-linux-glibc2.12-x86_64

3.修改目录权限

chown -R mysql.mysql mysql-5.7.31-linux-glibc2.12-x86_64

二、停从库流量和实例并备份数据

1.检查表是否损坏

mysql> select * from information_schema.tables where TABLE_COMMENT like ‘%repair%‘;
Empty set (0.10 sec)

2.检查从库主从是否正常及有无延迟

show slave status \G

3.停从库流量及io_thread

mysql> stop slave io_thread;
Query OK, 0 rows affected (0.00 sec)

4.数据全部落盘

待slave sql_thread完全应用后全部落盘

mysql> set global innodb_fast_shutdown=0;
Query OK, 0 rows affected (0.00 sec)

5.停从库

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

4.备份从库

通过 cp datadir 目录的方式来备份

cp -a data data0412

三、启动新版本MySQL

1.检查my.cnf配置文件

  • 1.1 检查basedir指向位置是否正确
  • 1.2 super_read_only 如果开启的话需要临时关闭,后期升级数据字典时候需要写入数据

2.检查启动脚本basedir指向是否正确

[root@study04 3308]# cat /etc/systemd/system/mysqld_3308.service | grep ExecStart
ExecStart=/software/mysql/bin/mysqld --defaults-file=/software/3308/my.cnf

3.启动msyql5.7.31

[root@study04 3308]# systemctl start mysqld_3308

[root@study04 3308]# ps -ef | grep mysqld | grep 3308
mysql     6703     1 10 14:58 ?        00:00:01 /software/mysql/bin/mysqld --defaults-file=/software/3308/my.cnf

四、运行 mysql_upgrade 升级数据字典

1.运行 mysql_upgrade

  • 1.出现Upgrade process completed successfully字样表示成功
  • 2.如果中间出现错误打断,需要再次运行
[root@study04 3308]# mysql_upgrade -uroot -S /software/3308/mysql.sock
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.engine_cost                                  OK
...
...
...
sbtest.sbtest3                                     OK
sbtest.sbtest4                                     OK
sys.sys_config                                     OK
Upgrade process completed successfully.
Checking if update is needed.

2.重启MySQL 5.7.31实例

[root@study04 3308]# systemctl restart mysqld_3308

五、升级后操作

1.确认升级是否成功

mysql> select version();
+------------+
| version()  |
+------------+
| 5.7.31-log |
+------------+
1 row in set (0.00 sec)

2.检查主从状态及延迟情况

mysql> show slave status \G

主库

  • 1.停主库流量
  • 2.待主从数据一致后进行主从切换
  • 3.讲流量指向升级后新主库
  • 4.原主库重复上述步骤升级

因为有悔,所以披星戴月;因为有梦,所以奋不顾身! 个人博客首发:easydb.net 微信公众号:easydb 关注我,不走丢!

MySQL主从架构小版本升级

MySQL主从架构小版本升级

上一篇:You can't access this shared folder because your organization's security policies block unauthenticated guest access. These policies help protect your PC


下一篇:Mysql 之最左原则