MySQL 8.0.20 升級筆記

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 作修正。


想在手機閱讀更多MySQL資訊?下載【香港矽谷】Android應用
分享到Facebook
技術平台: Nasthon Systems