暂无图片
暂无图片
2
暂无图片
暂无图片
暂无图片

MySQL 5.7 升级8.0过程

原创 Hulong Cui 2020-04-25
9071

为什么升级到MySQL8.0

1)基于安全考虑
2)基于性能和 稳定性考虑:
mgr复制 ,并行复制writeset 等功能,性能提升
3)新的功能:
Hash join ,窗口函数,DDL即时,joson 支持
4)原始环境中版本太多,统一版本。8.0版本基本已到稳定期。可以大量投入生产环境中

升级之前需要了解

1)数据库字典升级
schema,mysql,information_schema,performance_schema,sys
比如:密码测试 mysql_native_password → caching_sha2_password
2)关键词是不是兼容
https://dev.mysql.com/doc/refman/8.0/en/keywords.html
关键词 added in查询
3)SQL是不是兼容
Group by处理上的不兼容,触发器,存储过程
5.6 可以跑select id,count(*)from group by name;
5.7,8.0是不是允许的 sql_mode控制
4)数据文件存储格式是不是可以直接升级
Perconal 和 mysql 存储引擎一直,可以完全兼容
5)现有应用的兼容性是否满足
自定义函数,一些不规范的SQL语句等等
6)密码策略

What Is New in MySQL 8.0

作为DBA需要基本了解8.0的一些功能https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html
Added in 添加功能; Features Deprecated 弃用功能,Features Removed 移除功能

image.png
image.png
image.png

升级准备事项

已经了解8.0的特性,应对升级需要事先进行验证和准备工作

1)测试库升级,应用验证
2)数据库升级,末知问题发生
3)my.cnf配置信息调整
4)不兼容的操作方法,影响复制
5)一个平稳的过滤,列如先升级一个从库,到所有从库
6)最少停机时间,同样生产数据恢复到环境,进行模拟升级,评估时间
7)怎样进行数据验证:行数,表的数量 等等
8)考虑回滚方案
9)数据库备份

升级前检查
Mysql8.0还是提供了很多方便,不像之前一样5.6升级5.7那样。现在可以通过mysql shell进行确认。
https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-utilities-upgrade.html
##下面2种方式

#mysqlsh root:123456@192.168.244.130:3410 -e 'util.checkForServerUpgrade({"targetVersion":"8.0.19","configPath":"/etc/my3410.cnf"})'; MySQL JS > util.checkForServerUpgrade('root@192.168.244.130:3410', {"password":"123456", "targetVersion":"8.0.11", "configPath":"/etc/my3410.cnf"})

image.png
image.png
image.png

按照提示的要求进行更改
image.png

虽然shell做的很好,但还是存在一些缺陷。
比如以下内容都不会存在提示:
1.basedir,
2.sql_mode ,
3.半同步配置,
4.密码策略:default_authentication_plugin = mysql_native_password

开始升级

官网下载对应的tar包
https://downloads.mysql.com/archives/community/
下面是单机升级,高可用架构下 需要先升级从库,在逐步升级主库。

执行mysql_upgrade命令,会提示如下:

#/mysql8.0.19/bin/mysql_upgrade -uroot -p123456

image.png
在MySQL 8中mysql_upgrade客户端现已弃用。升级客户端执行的操作现在由服务器完成。
要升级,请使用较旧的数据目录启动新的 MySQL 二进制文件。自动修复用户表。升级后不需要重新启动。
所以必须在测试环境模拟准备对应SQL语句

***正确操作如下:

1)登录服务器进行正常关闭:innodb_fast_shutdown是默认是1,常常认为是安全关闭

##关闭innodb参数确认 mysql> show variables like 'innodb_fast_shutdown'; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | innodb_fast_shutdown | 1 | +----------------------+-------+ 1 row in set (0.00 sec) ##确保数据都刷到硬盘上,更改成0 mysql> set global innodb_fast_shutdown=0; Query OK, 0 rows affected (0.01 sec) mysql> shutdown; Query OK, 0 rows affected (0.00 sec)

*进行备份。

2)用mysql8.0.19客户端直接启动。
启动mysql服务

[root@ss30 bin]# /opt/mysql8.0.19/bin/mysqld_safe --defaults-file=/etc/my3400.cnf --user=mysql & [1] 15400 [root@ss30 bin]# 2020-04-25T13:07:16.591560Z mysqld_safe Logging to '/opt/data3400/logs/error.log'. 2020-04-25T13:07:16.636879Z mysqld_safe Starting mysqld daemon with databases from /opt/data3400/mysql ##打开另一个窗口查看error日志 [root@ss30 ~]# tail -f /opt/data3400/logs/mysql_error.log ##登录服务器确认 [root@ss30 ~]# mysql -uroot -p -S /opt/data3400/mysql/mysql.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.19 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> select version(); +-----------+ | version() | +-----------+ | 8.0.19 | +-----------+ 1 row in set (0.01 sec) ##无myisam引擎 mysql> SELECT table_schema,table_name,engine FROM information_schema.tables where engine!='InnoDB';

剩下的就是验证 和 业务确认否应用正常。

总结

整个从升级准备开始 到结束,中间包含很多细致的工作。比如版本确认,功能确认,测试,准备,备份,验证,高可用切换等等。前期需要投入很多精力进行准备,这样才能做到一步到位。
升级完,下一步踏上8.0的使用旅程。

最后修改时间:2022-12-27 13:52:34
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论