需要 MySQL 8.0 的新特性、性能改进或厂商支持截止时,把 5.7 升级到 8.0。升级不可逆,必须准备备份和回滚。
mysqlsh --uri root@db:3306 --js -e 'util.checkForServerUpgrade()'
SELECT @@version, @@sql_mode, @@character_set_server;
SHOW VARIABLES LIKE 'default_authentication_plugin';
SELECT table_schema, table_name, table_collation
FROM information_schema.tables WHERE table_collation LIKE 'utf8_%';
mysqldump -u root -p --single-transaction --routines --triggers \
--events --all-databases > all-5.7.sql
或使用 XtraBackup 物理备份。
systemctl stop mysqld
# 安装 8.0 包,保留旧数据目录备份
systemctl start mysqld
--upgrade 参数,不再有 mysql_upgrade):mysqld --upgrade=FORCE
ALTER USER 'app'@'%' IDENTIFIED WITH caching_sha2_password BY 'password';
SELECT VERSION(); 为 8.0。caching_sha2_password 需要新驱动;旧客户端可能连不上。GROUP BY 语义、utf8mb3 和排序规则变化。mysql_upgrade 在 8.0.16+ 已移除。mysql / mysqlsh — 连接与检查mysqldump — 备份percona-xtrabackup — 物理备份