• Post author:
  • Post category:mysql
  • Post comments:0评论
11

一、升级需知

  升级主要有两种方式:一是In-place就地,即在原服务器上,将原版本升级到新版本,风险较大,不推荐;二是Mergeing(Logical)迁移,即原服务器不动,准备一台相同的服务器,其中部署要升级的新版本数据库,通过备份或者主从将数据拉取到新环境中,再用新版本去加载旧版本的数据。
  推荐第二种方式,风险较小。当然不管哪种方式升级,都应该先做备份。
  升级注意事项:

  -  仅支持GA版本之间升级。
  -  5.6 → 5.7 ,建议先将5.6升级至最新版,再升级到5.7。
  -  不支持跳版本升级。例如,不支持5.5直接升级到5.7。
  -  5.5 → 5.7 ,建议先将5.5 升级至最新,再从5.5 → 5.6最新,再5.6 → 5.7 最新。
  -  在同一个发行版系列中,例如支持5.7.x → 5.7.y,也支持跳发行版本,如从5.7.x → 5.7.z。
  -  回退方案要提前考虑好,最好升级前要备份(特别是往8.0版本升级)。
  -  降低停机时间(停业务的时间),在业务不繁忙期间升级,做好足够的预演。

官方文档:https://dev.mysql.com/doc/refman/5.7/en/upgrading.html

二、In-place升级方式

整体流程:

  安装新版本数据库软件
  关闭原数据库业务(挂维护页)
  备份原数据库数据
  使用新版本数据库软件加载旧版本数据启动
  正常重启数据库
  验证各项功能是否正常
  业务恢复

  接下来我们来进行升级演示,因为是模拟环境,数据库中没有数据,所以不做备份,以下只演示升级操作。实际环境还需谨慎谨慎再谨慎。

1、5.6.48 → 5.7.28

  现有5.6.48版本数据库,需要升级到5.7.28。其数据库软件目录为/data/app/mysql,数据目录为/data/3306/data。

1、安装5.7.28数据库
[root@db01 ~]# tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /data/app/

2、优雅关闭原库
[root@db01 ~]# vim /etc/my.cnf     //添加innodb那个配置,即关闭数据库时将未写入数据全部写入落盘
[mysqld]
user=mysql
basedir=/data/app/mysql
datadir=/data/3306/data
socket=/tmp/mysql.sock
innodb_fast_shutdown=0

[root@db01 ~]# /data/app/mysql/support-files/mysql.server stop

3、使用高版本软件去加载低版本数据启动
[root@db01 app]# ll         //这里做了软链接,直接替换即可。方便不用更改systemd的mysql服务配置文件和环境变量。
total 0
lrwxrwxrwx.  1 root  root   35 Oct 15 02:40 mysql -> mysql-5.6.48-linux-glibc2.12-x86_64
drwxr-xr-x. 13 mysql mysql 205 Oct 15 02:42 mysql-5.6.48-linux-glibc2.12-x86_64
drwxr-xr-x.  9 mysql mysql 129 Oct 14 08:35 mysql-5.7.28-linux-glibc2.12-x86_64
[root@db01 app]# rm -f mysql
[root@db01 app]# ln -s mysql-5.7.28-linux-glibc2.12-x86_64 mysql
[root@db01 app]# ll
total 0
lrwxrwxrwx.  1 root  root   35 Oct 15 03:03 mysql -> mysql-5.7.28-linux-glibc2.12-x86_64
drwxr-xr-x. 13 mysql mysql 205 Oct 15 02:42 mysql-5.6.48-linux-glibc2.12-x86_64
drwxr-xr-x.  9 mysql mysql 129 Oct 14 08:35 mysql-5.7.28-linux-glibc2.12-x86_64

[root@db01 app]# /data/app/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables --skip-networking &

4、升级
[root@db01 app]# /data/app/mysql/bin/mysql_upgrade -S /tmp/mysql.sock --force

5、重启数据库到正常状态  
[root@db01 app]# /data/app/mysql/support-files/mysql.server restart

6、连接测试
[root@db01 app]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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> 

2、5.7.28 → 8.0.20

延续上面环境。升级到8.0的需知:

  -  升级前可以使用mysql-shell工具进行预检查,预估当前版本是否可以升级到指定的8.0.X版本,以及升级后要做的改动。
  -  不需要手动mysql_upgrade 
  -  升级到8.0.X版本后,是不能回退,升级请务必备份
1、安装8.0.20数据库
[root@db01 ~]# tar xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz -C /data/app

2、获取安装对应版本的mysql-shell
[root@db01 ~]# wget https://downloads.mysql.com/archives/get/p/43/file/mysql-shell-8.0.20-1.el7.x86_64.rpm
[root@db01 ~]# yum localinstall -y mysql-shell-8.0.20-1.el7.x86_64.rpm

3、预检查
[root@db01 ~]# mysqlsh root:000000@localhost:3306 -e "util.checkForServerUpgrade()"

4、优雅关闭原库
[root@db01 ~]# /data/app/mysql/support-files/mysql.server stop

5、使用高版本软件去加载低版本数据启动
[root@db01 app]# ll
total 0
lrwxrwxrwx.  1 root  root   35 Oct 15 03:34 mysql -> mysql-5.7.28-linux-glibc2.12-x86_64
drwxr-xr-x.  9 mysql mysql 129 Oct 14 08:35 mysql-5.7.28-linux-glibc2.12-x86_64
drwxr-xr-x.  9 mysql mysql  129 Oct 15 04:16 mysql-8.0.20-linux-glibc2.12-x86_64
[root@db01 app]# rm -f mysql
[root@db01 app]# ln -s mysql-8.0.20-linux-glibc2.12-x86_64 mysql
[root@db01 app]# ll
total 0
lrwxrwxrwx.  1 root  root   35 Oct 15 04:17 mysql -> mysql-8.0.20-linux-glibc2.12-x86_64
drwxr-xr-x.  9 mysql mysql 129 Oct 14 08:35 mysql-5.7.28-linux-glibc2.12-x86_64
drwxr-xr-x.  9 mysql mysql  129 Oct 15 04:16 mysql-8.0.20-linux-glibc2.12-x86_64

[root@db01 app]# /data/app/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables --skip-networking &

6、重启数据库到正常状态  
[root@db01 app]# /data/app/mysql/support-files/mysql.server restart

7、连接测试
[root@db01 app]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.20 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> 
11

发表评论

验证码: 13 − = 10