寫在開始:
1,非專業的DBA升級數據庫,有條件的換個機器測試一遍;沒條件的搭個虛擬機多試試,一定不要想當然,不然會死的很慘。
2,不能跳版,死了活該。
進入正題,升級數據庫,不要着急,一步步慢慢走:
1,仔細查看目標版本的 release notes,看看各項變更,有沒有影響自己的;
2,備份數據庫,以防各種萬一:
1)Dumping 數據爲 SQL 格式:
mysqldump -u root -p --all-databases --events > dump.sql
2)備份配置文件tar cvfvz mysql_conf.tgz /etc/mysql
3)備份lib庫tar cvfvz mysql_data.tgz /var/lib/mysql
3,關閉數據庫
1)設置 innodb_fast_shutdown 爲 0,slow模式可以確保 buffer 中的數據都能寫到 file 中,保證數據的完整性
mysql -u root -p --execute="set global innodb_fast_shutdown=0"
2)關閉數據庫mysqladmin -u root -p shutdown
4,升級數據庫
1)安裝 mysql apt repo
附如下版本的下載路徑:http://dev.mysql.com/downloads/repo/apt/
wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
sudo dpkg -i mysql-apt-config_0.7.3-1_all.deb
選擇需要的版本(可選:5.6/5.7 server)。如果選錯了,以後可再改:sudo dpkg-reconfigure mysql-apt-config
2)更新源並安裝
sudo apt-get update
sudo apt-get install mysql-server
安裝過程中會提示 my.conf 修改,差異的地方需要自行記錄下來,比如字符集,需要再修改回去:
如下是修改字符集的片段:
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
修改配置文件需要重啓數據庫,修改後檢查下狀態和版本:
sudo service mysql status
dpkg -l | grep mysql | grep ii
3)使用 mysqld_safe 配置數據目錄:mysqld_safe --user=mysql --datadir=/var/lib/mysql
4)mysql_upgrade:mysql_upgrade -u root -p
5,覈對數據
寫在最後:
1,怎麼導入備份?
mysql -u root -p
mysql> source dump.sql
2,升級中的問題:
問題1:reload dump 文件的時候,提示:
ERROR 1449 (HY000) at line 3430: The user specified as a definer ('xxxx'@'%') does not exist
方法:mysql>FLUSH PRIVILEGES;
之後重新執行 reload dump 操作,注意 root 密碼已改爲源庫密碼。
問題2:apt 升級安裝的時候,提示:
No directory, logging in with HOME=/
mysqld_safe Can't log to error log and syslog at the same time. Remove all --log-error configuration options for --syslog to take effect.
方法:歡迎回復:)