MySQL版本升級問題
由于OpenSSL等一些安全漏洞的原因,需要升級MySQL版本伶氢。
原本MySQL 5.7.30是使用安裝包安裝的俊嗽,計(jì)劃使用安裝包升級補(bǔ)丁5.7.33,升級過程中2個(gè)步驟遇到認(rèn)證問題:
第一個(gè)是在備份數(shù)據(jù)庫的時(shí)候英融,安裝包明知是升級盏檐,卻不用配置的密碼執(zhí)行mysqldump歇式,日志:
Backup files will be dumped to "C:\ProgramData\MySQL\MySQL Server 5.7\Backup\mysql_dump-2021-02-24T16.49.36.sql".
Starting process with command: C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqldump.exe --user=root --host=localhost --port=3306 --default-character-set=utf8 --routines --events --single-transaction=TRUE --all-databases --result-file="C:\ProgramData\MySQL\MySQL Server 5.7\Backup\mysql_dump-2021-02-24T16.49.36.sql"...
mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: NO) when trying to connect
Process for mysqldump, with ID 7640, was run successfully and exited with code 2.
Ended configuration step: Backing up MySQL database
只好在配置文件中加入
skip-grant-tables=1
但是到執(zhí)行安全配置時(shí)再次因?yàn)檎J(rèn)證問題失敗。
日志:
Beginning configuration step: Applying security settings
Attempting to update security settings.
Unable to update security settings. Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'@'localhost' (using password: NO)
Ended configuration step: Applying security settings
刪除所有ProgramData下的配置仍然失敗胡野,遂放棄5.7.30→5.7.33的升級安裝材失,索性升級最新的8.0.22(zip版)。
備份數(shù)據(jù)庫
使用舊版本運(yùn)行mysqldump.exe硫豆,字符集指定utf8mb4龙巨,如果只寫utf8,可能產(chǎn)生utf8mb3和utf8mb4的混淆熊响。以下以gitea數(shù)據(jù)庫為例:
mysqldump.exe --user=root -p --host=localhost --port=3306 --default-character-set=utf8mb4 --routines --events --single-transaction=TRUE --databases gitea --result-file="D:\backup\mysql_dump-gitea.sql"
還原數(shù)據(jù)庫
對新版本mysql進(jìn)行初始化旨别、新建服務(wù)等操作,停止舊版本服務(wù)耘眨,然后執(zhí)行g(shù)itea數(shù)據(jù)庫的還原:
mysqld --initialize --console
mysql -u root -p < D:\backup\mysql_dump-gitea.sql
執(zhí)行的時(shí)間視數(shù)據(jù)量大小昼榛。
總結(jié)
通過mysqldump導(dǎo)出數(shù)據(jù)庫的方式可以比較簡單的完成MySQL 5.7到8.0版本的升級工作。本質(zhì)上就是新版本安裝配置+數(shù)據(jù)遷移剔难。
注:這里都是INNODB的數(shù)據(jù)庫類型胆屿,不涉及與MyISAM的轉(zhuǎn)換。數(shù)據(jù)無價(jià)偶宫,謹(jǐn)慎操作非迹!