前言
- 示例以 5.7.34 升级到 5.7.37 为例
- CentOS 7.8
- 二进制方式升
- 标准部署 data目录单独存储 ,basedir固定软连接,在升级比较方便只需要更换软链接即可。
升级步骤
- 仅演示了 inplace 模式
- 也可使用逻辑模式进行升级(导入导出)
1.检查XA事务
# XA检查是否有值
mysql> XA RECOVER;
Empty set (0.00 sec)
# 若有值,则需要 COMMIT 或 ROLLBACK xid
# mysql> XA COMMIT xid;
# 或
# mysql> XA ROLLBACK xid;
2.innodb_fast_shutdown设置为0
通过慢速关机,在关机InnoDB前执行完全清除和更改缓冲区合并,以确保在版本之间文件格式存在差异的情况下数据文件已做好充分准备。
mysql -h localhost -u root -p -P3306 --execute="SET GLOBAL innodb_fast_shutdown=0"
3.关闭MySQL服务器
# 关闭MySQl
service mysqld stop
或
mysqladmin -h 127.0.0.1 -u root -p shutdown
4.升级前备份
备份前注意看下容量是否足够
# 备份下数据文件,防止有问题需回滚,备份前注意看下容量是否足够,拷贝时长看数据大小
cp -rp /data/mysql3306 /data/mysql3306_bak
5.升级 MySQL 二进制安装或软件包
# cd 到安装文件目录下
tar -zxvf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local
# 原来的软链
lrwxrwxrwx. 1 root root 46 Nov 12 2019 mysql -> /usr/local/mysql-5.7.34-linux-glibc2.12-x86_64
# 删除软链
cd /usr/local
unlink mysql
# 重建软链
ln -s mysql-5.7.37-linux-glibc2.12-x86_64 mysql
# 新的软链,链接到了新版本
lrwxrwxrwx 1 root root 35 Jun 24 15:16 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64
6.启动MySQL
service mysqld start
或
mysqld_safe --defaults-file=/etc/my.cnf --user=mysql 2>&1
7.执行inplace升级
需要 root 最大权限
# 检查下是否当前客户端符合当前的版本,需要与当前升级到的版本相同
[root@VM_0_9_centos bin]# mysql --version
mysql Ver 14.14 Distrib 5.7.37, for linux-glibc2.12 (x86_64) using EditLine wrapper
[root@VM_0_9_centos bin]# mysql_upgrade --version
mysql_upgrade Ver 2.0 Distrib 5.7.37, for linux-glibc2.12 (x86_64)
[root@VM_0_9_centos bin]# mysql_upgrade -uroot -p
Enter password:
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
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
The sys schema is already up to date (version 1.5.2).
Checking databases.
employees.departments OK
employees.dept_emp OK
employees.dept_manager OK
employees.employees OK
employees.salaries OK
employees.titles OK
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
8.加载新的帮助表
mysql -uroot -p mysql < /usr/local/mysql/share/fill_help_tables.sql
9.升级完成后再次重启
service mysqld restart
降级步骤
- 仅演示了 inplace 模式
- 也可使用逻辑模式进行(导入导出)
1.检查XA事务
# XA检查是否有值
mysql> XA RECOVER;
Empty set (0.00 sec)
# 若有值,则需要 COMMIT 或 ROLLBACK xid
# mysql> XA COMMIT xid;
# 或
# mysql> XA ROLLBACK xid;
2.innodb_fast_shutdown设置为0
通过慢速关机,在关机InnoDB前执行完全清除和更改缓冲区合并,以确保在版本之间文件格式存在差异的情况下数据文件已做好充分准备。
mysql -h localhost -u root -p -P3306 --execute="SET GLOBAL innodb_fast_shutdown=0"
3.关闭MySQL服务器
# 关闭MySQl
service mysqld stop
或
mysqladmin -h 127.0.0.1 -u root -p shutdown
4.升级前备份
备份前注意看下容量是否足够
# 备份下数据文件,防止有问题需回滚,备份前注意看下容量是否足够,拷贝时长看数据大小
cp -rp /data/mysql3306 /data/mysql3306_bak_20220101
5.升级 MySQL 二进制安装或软件包
# 删除软链
cd /usr/local
unlink mysql
# 使用旧版本重建软链
ln -s mysql-5.7.34-linux-glibc2.12-x86_64 mysql
# 新的软链,链接到了新版本
lrwxrwxrwx 1 root root 35 Jun 24 15:16 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64
6.启动MySQL
service mysqld start
或
mysqld_safe --defaults-file=/etc/my.cnf --user=mysql 2>&1
7.执行inplace降级
需要 root 最大权限
# 检查命令文件是否对应的版本
[root@VM_0_9_centos local]# mysql --version
mysql Ver 14.14 Distrib 5.7.34, for linux-glibc2.12 (x86_64) using EditLine wrapper
[root@VM_0_9_centos local]# mysql_upgrade --version
mysql_upgrade Ver 2.0 Distrib 5.7.34, for linux-glibc2.12 (x86_64)
# 执行降级
[root@VM_0_9_centos local]# mysql_upgrade -uroot -p
Enter password:
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
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
The sys schema is already up to date (version 1.5.2).
Checking databases.
employees.departments OK
employees.dept_emp OK
employees.dept_manager OK
employees.employees OK
employees.salaries OK
employees.titles OK
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.
8.升级完成后再次重启
service mysqld restart