共計(jì) 3347 個(gè)字符,預(yù)計(jì)需要花費(fèi) 9 分鐘才能閱讀完成。
這篇文章主要講解了“MySQL 5.7 怎么升級到 8.0”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著丸趣 TV 小編的思路慢慢深入,一起來研究和學(xué)習(xí)“MySQL 5.7 怎么升級到 8.0”吧!
為什么升級到 MySQL 8.0
基于安全考慮
基于性能和 穩(wěn)定性考慮:
mgr 復(fù)制,并行復(fù)制 writeset 等功能,性能提升
新的功能:
Hash join,窗口函數(shù),DDL 即時(shí),json 支持
原始環(huán)境中版本太多,統(tǒng)一版本
8.0 版本基本已到穩(wěn)定期,可以大量投入生產(chǎn)環(huán)境中
升級之前需要了解
數(shù)據(jù)庫字典升級
schema,mysql,information_schema,performance_schema,sys
比如:密碼測試 mysql_native_password rarr; caching_sha2_password
2. 關(guān)鍵詞是不是兼容
https://dev.mysql.com/doc/refman/8.0/en/keywords.html
關(guān)鍵詞 added in 查詢
3. SQL 是不是兼容
Group by 處理上的不兼容,觸發(fā)器,存儲(chǔ)過程
5.6 可以跑 select id,count(*)from group by name;
5.7,8.0 是不是允許的 sql_mode 控制
4. 數(shù)據(jù)文件存儲(chǔ)格式是不是可以直接升級
Perconal 和 mysql 存儲(chǔ)引擎一直,可以完全兼容
5. 現(xiàn)有應(yīng)用的兼容性是否滿足
自定義函數(shù),一些不規(guī)范的 SQL 語句等等
6. 密碼策略
What Is New in MySQL 8.0
作為 DBA 需要基本了解 8.0 的一些功能
Added in 添加功能
Features Deprecated 棄用功能
Features Removed 移除功能
升級準(zhǔn)備事項(xiàng)
已經(jīng)了解 8.0 的特性,應(yīng)對升級需要事先進(jìn)行驗(yàn)證和準(zhǔn)備工作
測試庫升級,應(yīng)用驗(yàn)證
數(shù)據(jù)庫升級,末知問題發(fā)生
my.cnf 配置信息調(diào)整
不兼容的操作方法,影響復(fù)制
一個(gè)平穩(wěn)的過濾,列如先升級一個(gè)從庫,到所有從庫
最少停機(jī)時(shí)間,同樣生產(chǎn)數(shù)據(jù)恢復(fù)到環(huán)境,進(jìn)行模擬升級,評估時(shí)間
怎樣進(jìn)行數(shù)據(jù)驗(yàn)證:行數(shù),表的數(shù)量 等等
考慮回滾方案
數(shù)據(jù)庫備份
升級前檢查
Mysql8.0 還是提供了很多方便,不像之前一樣 5.6 升級 5.7 那樣。現(xiàn)在可以通過 mysql shell 進(jìn)行確認(rèn)。
下面 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})
按照提示的要求進(jìn)行更改
雖然 shell 做的很好,但還是存在一些缺陷。
比如以下內(nèi)容都不會(huì)存在提示:
1. basedir,
2. sql_mode ,
3. 半同步配置,
4. 密碼策略:default_authentication_plugin = mysql_native_password
開始升級
官網(wǎng)下載對應(yīng)的 tar 包
https://downloads.mysql.com/archives/community/
下面是單機(jī)升級,高可用架構(gòu)下 需要先升級從庫,在逐步升級主庫。
執(zhí)行 mysql_upgrade 命令, 會(huì)提示如下:
#/mysql8.0.19/bin/mysql_upgrade -uroot -p123456
在 MySQL 8 中 mysql_upgrade 客戶端現(xiàn)已棄用。升級客戶端執(zhí)行的操作現(xiàn)在由服務(wù)器完成。
要升級, 請使用較舊的數(shù)據(jù)目錄啟動(dòng)新的 MySQL 二進(jìn)制文件。自動(dòng)修復(fù)用戶表。升級后不需要重新啟動(dòng)。
所以必須在測試環(huán)境模擬準(zhǔn)備對應(yīng) SQL 語句
正確操作如下:
1) 登錄服務(wù)器進(jìn)行正常關(guān)閉:innodb_fast_shutdown 是默認(rèn)是 1,常常認(rèn)為是安全關(guān)閉
關(guān)閉 innodb 參數(shù)確認(rèn)
mysql show variables like innodb_fast_shutdown +----------------------+-------+| Variable_name | Value |+----------------------+-------+| innodb_fast_shutdown | 1 |+----------------------+-------+1 row in set (0.00 sec)
確保數(shù)據(jù)都刷到硬盤上,更改成 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) * 進(jìn)行備份。
2)用 mysql8.0.19 客戶端直接啟動(dòng)
啟動(dòng) mysql 服務(wù)
[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 ## 打開另一個(gè)窗口查看 error 日志 [root@ss30 ~]# tail -f /opt/data3400/logs/mysql_error.log
登錄服務(wù)器確認(rèn)
[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
剩下的就是驗(yàn)證 和 業(yè)務(wù)確認(rèn)否應(yīng)用正常。
感謝各位的閱讀,以上就是“MySQL 5.7 怎么升級到 8.0”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對 MySQL 5.7 怎么升級到 8.0 這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!