MySQL 8.0.20 升級筆記

這陣子在處理 MySQL 5.6 -> 5.7 -> 8.0 升級的事,踩到一些地雷;紀錄一下。

目前新版的 MySQL 5.7 & 8.0 在全新安裝時會隨機產生 root 的密碼,並把密碼寫在 log 裡面。
這行為在自動化佈署時會遇上點麻煩,而避免隨機產生 root 密碼的方式是在 script 作這樣的事:

...
mysqld --initialize-insecure
systemctl start mysqld
echo "ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY '##########';" | mysql
...

(5.7 -> 8.0)升級方面,第一個變化是 mysql_upgrade 不需要執行了;server 在啟動時會檢查,並自行升版。

原本在 5.7 版仍能使用的幾個 Server System Variables 在 8.0 版必須移除:

  • query_cache_type = 0
  • query_cache_size = 0
  • innodb_large_prefix = 1
  • innodb_file_format = Barracuda

expire_logs_days 也應移除,改用 binlog_expire_logs_seconds
我另外在 8.0 版補上這兩個設定:

  • mysqlx = 0
  • default_authentication_plugin = mysql_native_password

5.7 -> 8.0 的預設語系/字元集有變化:

character_set_servercollation_server
MySQL 5.7latin1latin1_swedish_ci
MySQL 8.0utf8mb4utf8mb4_0900_ai_ci

特別提 8.0.20 是因為使用 Percona XtraBackup 時踩到地雷(Ref. percona-xtrabackup-80 does not work with mysql 8.0.20);原因是 Redo log 格式被更改了,Changes in MySQL 8.0.20 (2020-04-27, General Availability) 裡面有這段:

InnoDB: Redo log records for modifications to undo tablespaces increased in size in MySQL 8.0 due to a change in undo tablespace ID values, which required additional bytes. The change in redo log record size caused a performance regression in workloads with heavy write I/O. To address this issue, the redo log format was modified to reduce redo log record size for modifications to undo tablespaces. (Bug #29536710)

(有興趣深究的可以看看這個 commit

Percona XtraBackup – Documentation 裡面也有這段說明:

Due to changes in MySQL 8.0.20 released by Oracle at the end of April 2020, Percona XtraBackup 8.0, up to version 8.0.11, is not compatible with MySQL version 8.0.20 or higher, or Percona products that are based on it: Percona Server for MySQL and Percona XtraDB Cluster.

另外一顆地雷是 Drupal 7 在連線初始化時會設定 SQL mode,但 NO_AUTO_CREATE_USER 在 8.0 被拿掉了;目前先用 這個 comment 裡面夾帶的 patch 作修正。