Mysql 5.6升级5.7

#####mysql5.6升级5.7#####
###升级
#停止主机上的mysql5.6版本的服务
--If you use InnoDB, configure MySQL to perform a slow shutdown by setting innodb_fast_shutdown to 0.
	With a slow shutdown, InnoDB performs a full purge and change buffer merge before shutting down, which ensures that data files are fully prepared in case of file format differences between releases.
mysql -u root -p --execute="SET GLOBAL innodb_fast_shutdown=0"
#备份5.6版本的datadir目录
cp -r mysql_data mysql_data_cz_test

#安装5.7
[root@name01 ~]# tar zxvf mysql-5.7.27-el7-x86_64.tar.gz
mv mysql-5.7.27-el7-x86_64 /usr/local/mysql5.7

#指向mysql5.6的数据文件目录
cd /usr/local/mysql5.7/support-files
vim mysql.server 
basedir=/usr/local/mysql5.7       //5.7程序目录
datadir=/usr/local/mysql_data     //5.6的数据文件位置

#修改my.cnf文件
vim /etc/my.cnf
basedir = /usr/local/mysql5.7
datadir = /usr/local/mysql_data

#启动mysql5.7
cd /usr/local/mysql5.7/support-files
./mysql.server start

#查看日志会发现有很多error 
2019-08-12T09:03:27.915488Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_global_by_event_name' has the wrong structure
2019-08-12T09:03:27.915554Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_account_by_event_name' has the wrong structure
2019-08-12T09:03:27.915612Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_host_by_event_name' has the wrong structure
2019-08-12T09:03:27.915670Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_thread_by_event_name' has the wrong structure
2019-08-12T09:03:27.915723Z 0 [ERROR] Native table 'performance_schema'.'memory_summary_by_user_by_event_name' has the wrong structure
2019-08-12T09:03:27.915766Z 0 [ERROR] Native table 'performance_schema'.'table_handles' has the wrong structure
2019-08-12T09:03:27.915831Z 0 [ERROR] Native table 'performance_schema'.'metadata_locks' has the wrong structure
2019-08-12T09:03:27.915889Z 0 [ERROR] Native table 'performance_schema'.'replication_connection_configuration' has the wrong structure
2019-08-12T09:03:27.915940Z 0 [ERROR] Native table 'performance_schema'.'replication_group_members' has the wrong structure
2019-08-12T09:03:27.916034Z 0 [ERROR] Native table 'performance_schema'.'replication_connection_status' has the wrong structure
2019-08-12T09:03:27.916089Z 0 [ERROR] Native table 'performance_schema'.'replication_applier_configuration' has the wrong structure

#执行升级,重建系统表
--参数-s,只更新系统表,如果不加,会把库里所有的表,以5.7的方式,进行重建。数据库二进制文件,是兼容的,无需升级。当一些老版本的存储格式,
需要特性来提升性能时,才可不加-s
[root@name01 ~]# cd /usr/local/mysql5.7/
[root@name01 bin]# ./mysql_upgrade -p -s --如果执行失败    ./mysql_upgrade -p -u system(是一个有权限的用户)  -s 

#重启mysql5.7,升级完成,检查连接及数据。


###降级
#拷贝回原来的数据文件,并附权限
cp -r mysql_data_cz_test mysql_data 
chown -R mysql.mysql mysql_data

#修改my.cnf
basedir = /usr/local/mysql5.6  //修改回5.6的mysql程序

#启动mysql


叶问(20190815):MySQL 5.6升级5.7都有什么注意事项

一、升级方式

MySQL升级的方式一般来说有两种
1、通过inplace方式原地升级,升级系统表
2、通过新建实例,高版本作为低版本的从库进行滚动升级

MySQL5.7版本做了非常多的改变,升级5.6到5.7时需要考虑兼容性,避免升级到5.7之后因为种种参数设置不正确导致业务受影响,建议首先逐一查看release note

二、需要注意的参数及问题:

1、sql_mode:MySQL 5.7采用严格模式,例如ONLY_FULL_GROUP_BY等
2、innodb_status_output_locks:MySQL 5.7支持将死锁信息打印到error log(其实这个参数MySQL 5.6就已支持)
3、innodb_page_cleaners:MySQL 5.7将脏页刷新线程从master线程独立出来了,对应参数为innodb_page_cleaners
4、innodb_strict_mode:控制CREATE TABLE, ALTER TABLE, CREATE INDEX, 和 OPTIMIZE TABLE的语法问题
5、show_compatibility_56=ON:控制show变量及状态信息输出,如果未开启show status 命令无法获取Slave_xxx 的状态
6、log_timestamps:控制error log/slow_log/genera log日志的显示时间,该参数可以设置为:UTC 和 SYSTEM,但是默认使用 UTC
7、disable_partition_engine_check:在表多的情况下可能导致启动非常慢
8、range_optimizer_max_mem_size:范围查询优化参数,这个参数限制范围查询优化使用的内存,默认8M
9、MySQL 5.7新增优化器选项derived_merge=on,可能导致SQL全表扫描,而在MySQL 5.6下可能表现为auto key
10、innodb_undo_directory && innodb_undo_logs:MySQL 5.7支持将undo从ibdata1独立出来(只支持实例初始化,不支持在线变更)
11、主从复制问题:MySQL5.7到小于5.6.22的复制存在bug(bug 74683)
12、SQL兼容性问题:SQL在MySQL 5.7和MySQL 5.6环境下结果可能不一致,因此建议获取线上SQL,在同样数据的环境下,在两个实例运行获取到的结果计算hash,比较hash值做兼容性判断

三、友情提醒

1、升级前一定要做好备份!!!
2、升级正式环境前提前在测试环境进行仔细测试,确认无误以后再升级正式环境
3、做好相应的回退方案

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章