一、環境說明
- 作業系統版本centos7.6
[[email protected] opt]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
- 更新前版本為mysql 5.7.26,安裝方式為rpm安裝
[[email protected] opt]# mysqld -V
[[email protected] mysql]# mysqld -V
mysqld Ver 5.7.26 for Linux on x86_64 (MySQL Community Server (GPL))
- 更新後版本為mysql 5.7.33,通過rpm包安裝方式更新
[[email protected] mysql]# mysqld -V
mysqld Ver 5.7.33 for Linux on x86_64 (MySQL Community Server (GPL))
二、更新步驟
如果伺服器未聯網,可以登入官網下載下傳後上傳,下載下傳所需版本的安裝包及依賴包,然後從第4步開始更新步驟。
1、下載下傳MySQL官方的 Yum Repository
[[email protected] opt]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2、安裝MySQL官方的 Yum Repository
[[email protected] opt]# rpm -ivh mysql57-community-release-el7-10.noarch.rpm
3、下載下傳mysql-community-server安裝包及依賴包
[[email protected] opt]# yumdownloader --resolve mysql-community-server
4、檢查确認目前安裝的mysql包
[[email protected] opt]# rpm -qa |grep mysql
mysql-community-common-5.7.26-1.el7.x86_64
mysql-community-client-5.7.26-1.el7.x86_64
mysql-community-server-5.7.26-1.el7.x86_64
mysql-community-libs-5.7.26-1.el7.x86_64
5、備份資料庫
備份前設定鎖,隻讀
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
備份整個資料庫
[[email protected] tmp]# mysqldump -u root -p --add-drop-table --routines --events --all-databases --force > dataall.sql
Enter password:
[[email protected] tmp]#
6、備份配置檔案
[[email protected] tmp]# cp /etc/my.cnf /tmp/my.cnf.bak
7、關閉緩存
[[email protected] tmp]# mysql -u root -p --execute=“SET GLOBAL innodb_fast_shutdown=0”
Enter password:
8、更新mysql-server
親測可以不關閉資料庫,更新完成後資料庫将自動重新開機。
[[email protected] mysql]# rpm -Uvh mysql-community-common-5.7.33-1.el7.x86_64.rpm --nodeps
warning: mysql-community-common-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:mysql-community-common-5.7.33-1.e################################# [ 50%]
Cleaning up / removing…
2:mysql-community-common-5.7.26-1.e################################# [100%]
[[email protected] mysql]# rpm -Uvh mysql-community-server-5.7.33-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:mysql-community-server-5.7.33-1.e################################# [ 50%]
Cleaning up / removing…
2:mysql-community-server-5.7.26-1.e################################# [100%]
9、檢查更新後資料庫版本
[[email protected] mysql]# mysqld -V
mysqld Ver 5.7.33 for Linux on x86_64 (MySQL Community Server (GPL))
10、關閉隻讀鎖
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
11、執行mysql更新檢查
[[email protected] mysql]# mysql_upgrade -uroot -p
Enter password:
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
…
Upgrade process completed successfully.
Checking if update is needed.
12、更新mysql用戶端
[[email protected] opt]# rpm -Uvh mysql-community-client-5.7.33-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing… ################################# [100%]
Updating / installing…
1:mysql-community-client-5.7.33-1.e################################# [ 50%]
Cleaning up / removing…
2:mysql-community-client-5.7.26-1.e################################# [100%]
[[email protected] opt]# mysql -V
mysql Ver 14.14 Distrib 5.7.33, for Linux (x86_64) using EditLine wrapper
三、FAQ
1、執行mysql-community-common包更新時報錯
error: Failed dependencies:
mysql-community-common(x86-64) = 5.7.26-1.el7 is needed by (installed) mysql-community-server-5.7.26-1.el7.x86_64
原因:common包被server依賴
解決方案:加上–nodeps參數執行更新