天天看點

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
[[email protected] ~]# 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
[[email protected] ~]# cd /usr/local/mysql5.7/
[[email protected] 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、做好相應的回退方案

           

繼續閱讀