MySQL 5.7升級8.0過程


為什么升級到MySQL 8.0

  1. 基於安全考慮
  2. 基於性能和 穩定性考慮:
    mgr復制 ,並行復制writeset 等功能,性能提升
  3. 新的功能:
    Hash join ,窗口函數,DDL即時,json 支持
  4. 原始環境中版本太多,統一版本
  5. 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 移除功能




升級准備事項

已經了解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"})

 
        

 
        


按照提示的要求進行更改

雖然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



在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.sockEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 10Server version: 8.0.19 MySQL Community Server - GPLCopyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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的使用旅程


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM