为什么升级到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 移除功能升级前检查
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"})
官网下载对应的tar包
https://downloads.mysql.com/archives/community/
下面是单机升级,高可用架构下 需要先升级从库,在逐步升级主库。执行mysql_upgrade命令,会提示如下:
#/mysql8.0.19/bin/mysql_upgrade -uroot -p123456 在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 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';
剩下的就是验证 和 业务确认否应用正常。