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、做好相應的回退方案

 

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