暂无图片
暂无图片
4
暂无图片
暂无图片
暂无图片

MySQL跨大、小版本升级最佳实践(5.7.22-5.7.39-8.0.28-8.0.30)

原创 OnTheRoad 2022-09-07
5246

1. 注意事项

1.1. 升级路径

  1. 仅支持 GA 版本之间的升级
  2. MySQL 5.7-> MySQL 8.0,建议升级至 5.7 最新版,再升级 8.0
  3. MySQL 5.6-> MySQL 5.7 -> MySQL 8.0,不支持跨大版本升级。
  4. MySQL 8.0.x -> MySQL 8.0.z,支持跨小版本升级。

1.2. MySQL Shell 升级检查

可通过 MySQL Shell 工具进行版本升级检查,以验证是否满足升级条件。该工具适用于 MySQL5.7 和 MySQL 8.0 的所有 GA 版本。

官方文档链接:https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-utilities-upgrade.html

1.2.1. MySQL Shell 安装

MySQL Shell 下载链接:https://dev.mysql.com/downloads/shell/

  1. 安装 MySQL Shell
sudo wget https://cdn.mysql.com//Downloads/MySQL-Shell/mysql-shell-8.0.30-linux-glibc2.12-x86-64bit.tar.gz sudo tar -xzvf mysql-shell-8.0.30-linux-glibc2.12-x86-64bit.tar.gz sudo mv mysql-shell-8.0.30-linux-glibc2.12-x86-64bit /usr/local/ sudo ln -s /usr/local/mysql-shell-8.0.30-linux-glibc2.12-x86-64bit /usr/local/mysql-shell sudo chown -R /usr/local/mysql-shell* cat ~/.bash_profile export PATH=$PATH:/usr/local/mysql-shell/bin
  1. 运行 MySQL Shell

可直接执行 mysqlsh,进入 cli 交互模式,在执行升级检查时,指定 用户名/密码

[mysql@localhost ~]$ mysqlsh MySQL Shell 8.0.30 Copyright (c) 2016, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type '\help' or '\?' for help; '\quit' to exit. MySQL JS >

也可在执行 mysqlsh 时,通过参数选项-u-p直接指定 用户名/密码

[mysql@localhost ~]$ mysqlsh -uroot -P5306 -p Please provide the password for 'root@localhost:5306': <输入 root 密码> MySQL localhost:5306 JS > \status MySQL Shell version 8.0.30 Connection Id: 10 Current schema: Current user: root@127.0.0.1 SSL: Not in use. Using delimiter: ; Server version: 5.7.22-log MySQL Community Server (GPL) Protocol version: Classic 10 Client library: 8.0.30 Connection: localhost via TCP/IP TCP port: 5306 Server characterset: utf8mb4 Schema characterset: utf8mb4 Client characterset: utf8mb4 Conn. characterset: utf8mb4 Result characterset: utf8mb4 Compression: Disabled Uptime: 11 hours 49 min 17.0000 sec Threads: 1 Questions: 371 Slow queries: 0 Opens: 616 Flush tables: 4 Open tables: 31 Queries per second avg: 0.008

以上信息显示,当前 MySQL 服务器版本为 MySQL 5.7.22 社区版

1.2.2. 升级检查

假设数据库 192.168.3.227 版本为 5.7.22,欲升级 8.0.30。则可通过如下几种方式检查升级。

【注意】
通过 configPath指定配置文件 my.cnf,可以检查新、旧版本冲突的配置项。

  1. 以交互模式,执行升级检查。
[mysql@localhost ~]$ mysqlsh MySQL Shell 8.0.30 Copyright (c) 2016, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type '\help' or '\?' for help; '\quit' to exit. MySQL JS > # 方式1: 检查 URI root@192.168.3.227:5306 处的 MySQL 服务器以升级到 MySQL 服务器版本 8.0.30。用户密码和配置文件路径作为选项字典的一部分提供 MySQL JS > util.checkForServerUpgrade('root@192.168.3.227:5306', {"password":"root", "targetVersion":"8.0.30", "configPath":"/etc/my.cnf"}) # 方式2: 检查 URI root@192.168.3.227:5306 处的 MySQL 服务器是否升级到与当前 MySQL Shell 版本号(默认)匹配的 MySQL 服务器版本号,并返回 JSON 输出以供进一步处理: MySQL JS > util.checkForServerUpgrade('root@192.168.3.227:5306', {"password":"root", "outputFormat":"JSON", "configPath":"/etc/my.cnf"})
  1. 以命令模式,执行升级检查。
# 方式1: 指定服务器的 my.cnf 配置文件,检查 MySQL 服务器 root@192.168.3.227:5306 是否升级到版本 8.0.30,并返回 JSON 输出: [mysql@localhost ~]$ mysqlsh -- util checkForServerUpgrade root@192.168.3.227:5306 --target-version=8.0.30 --output-format=JSON --config-path=/etc/my.cnf # 方式2:将连接信息用大括号括起来,作为 mysqlsh 的连接选项,检查 MySQL 服务器是否升级到版本 8.0.30,并返回 JSON 输出 [mysql@localhost ~]$ mysqlsh -- util check-for-server-upgrade { --user=root --host=192.168.3.227 --port=5306 } --target-version=8.0.30 --output-format=JSON --config-path=/etc/my.cnf # 方式3:使用套接字连接 MySQL 5.7 服务器,检查其是否能升级到与 MySQL Shell 匹配的 MySQL 服务器版本。 [mysql@localhost ~]$ mysqlsh --socket=/mysql/socket/mysql.sock --user=root -e "util.checkForServerUpgrade()"
  1. 关于升级检查工具的帮助
mysqlsh> util.help("checkForServerUpgrade")

【权限需求】

版本号低于 MySQL Shell 8.0.20 时,用于运行升级检查器实用程序的用户帐户必须具有 ALL 权限。从 MySQL Shell 8.0.21 开始,用户帐户需要 RELOADPROCESSSELECT 权限。

1.2.3. 调整冲突项

根据升级检查结果,手动纠正影响升级的配置项,其中可能需要关注的注意事项如下:

  1. MySQL 5.7 的默认身份验证插件为 mysql_native_password,而 MySQL 8.0 的默认身份验证插件变更为 cache_sha2_password。即 MySQL 全局系统变量 default_authentication_plugin 的默认值从 mysql_native_password 变为 caching_sha2_password。该变化仅影响升级后的新建用户,不影响存量用户。

若启用新的验证插件,则需要通过如下命令修改用户密码。

ALTER USER <用户名> IDENTIFIED WITH caching_sha2_password BY '<密码>';
  1. 如想继续保持适用 mysql_native_password 身份验证插件,可为 MySQL 服务器的配置文件(Linux 系统默认位置为 /etc/my.cnf)中增加如下参数。
[mysqld] default_authentication_plugin=mysql_native_password

【注意】
在 MySQL 8.0 版本中,用户验证方式配置项 default_authentication_plugin 已废弃。替换为 authentication_policy

  1. 需将分区表的存储引擎调整为 InnoDB

若数据库中存在存储引擎不是 InnoDB 的分区表,需将这些分区表的存储引擎调整为 InnoDB。命令语法如下:

ALTER TABLE <表名> ENGINE=InnoDB;
  1. 默认字符集已从 latin1 更改为 utf8mb4。将影响如下系统变量:

    • character_set_servercharacter_set_database 系统变量的默认值已从 latin1 更改为 utf8mb4
    • collat​​ion_servercollat​​ion_database 系统变量的默认值已从 latin1_swedish_ci 更改为 utf8mb4_0900_ai_ci
  2. 从 MySQL 8.0.11 开始,禁止使用与服务器初始化时使用的设置不同的 lower_case_table_names 设置来启动服务器。

更多需注意的事项,参考链接:https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html

1.3. 回退方案

  1. 执行物理备份。若升级失败,恢复物理备份,并将 /usr/local/mysql 软连接指向旧版 MySQL Server 目录;启动旧版 MySQL。
  2. 执行逻辑备份。若升级失败,搭建新版数据库,利用逻辑备份恢复数据。

2. 升级前备份

根据数据库大小,可选择备份方式:物理备份或逻辑备份。

2.1. 物理备份

查看数据目录位置,并执行物理备份

  1. 查看数据目录
[mysql@localhost local]$ mysql -uroot -proot -P5306 mysql> show global variables like '%datadir%'; +---------------+------------------+ | Variable_name | Value | +---------------+------------------+ | datadir | /mysql/database/ | +---------------+------------------+ 1 row in set (0.00 sec)
  1. 停机备份

设置 innodb_fast_shutdown=0,将数据库关闭方式调整为慢关闭。在 MySQL 主要版本之间升级或降级之前使用 慢关闭 技术,以便在升级过程更新文件格式时做好所有数据文件的准备。

# 1. 调整服务器为慢关闭,并停机 [mysql@localhost ~]$ mysql -u root -p --execute="SET GLOBAL innodb_fast_shutdown=0" [mysql@localhost ~]$ sudo systemctl stop mysqld # 2. 执行物理备份 [root@localhost ~]# tar -czvf /mysql/database_bak.tgz /mysql/database/ [root@localhost ~]# ls -l /mysql/ total 524 drwxr-xr-x. 2 mysql mysql 4096 Aug 26 23:53 bin-log drwxr-xr-x. 5 mysql mysql 4096 Aug 27 12:34 database -rw-r--r--. 1 root root 497132 Aug 27 12:53 database_bak.tgz drwxr-xr-x. 2 mysql mysql 4096 Aug 26 23:47 mysql-log drwxr-xr-x. 2 mysql mysql 4096 Aug 26 23:53 mysql-tmp drwxr-xr-x. 2 mysql mysql 4096 Aug 27 12:34 pid drwxr-xr-x. 2 mysql mysql 4096 Aug 26 23:47 redo-log drwxr-xr-x. 2 mysql mysql 4096 Aug 26 23:46 relay-log drwxr-xr-x. 2 mysql mysql 4096 Aug 27 12:34 socket drwxr-xr-x. 2 mysql mysql 4096 Aug 26 23:46 undo-log

2.2. 逻辑备份

[mysql@localhost ~]$ mysqldump -uroot -h<IP> -P<端口> -p --defaults-extra-file=/etc/my.cnf --set-gtid-purged=off --databases <DB1> <DB2> <DB3> | gzip >/mysqldata/backup/`date +%Y%m%d`_SumDB.sql.gz

3. 执行升级

适用于 5.7.x->5.7.395.7.39->8.0.288.0.28->8.0.30。其中,5.7.x->5.7.39 需执行 mysql_upgrade 完成系统库(如 mysql)的升级。

另需特别注意,新旧版本配置项的区别。一部分在 8.0.x 中已废弃的配置项,需在配置文件中去除。

MySQL 8.0 默认身份验证插件由 mysql_native_password 调整为 caching_sha2_password,为避免应用报错。升级至 MySQL 8.0 版本后,需在配置文件中增加配置项。

[mysqld] authentication_policy= mysql_native_password

【注意】
在 MySQL 8.0 版本中,用户验证方式配置项 default_authentication_plugin 已废弃。替换为 authentication_policy

3.1. 二进制包安装

[root@localhost ~]# export VERSION=5.7.39 [root@localhost ~]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-${VERSION}-el7-x86_64.tar.gz [root@localhost ~]# export VERSION=8.0.28 [root@localhost ~]# export VERSION=8.0.30 [root@localhost ~]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-${VERSION}-el7-x86_64.tar.gz [root@localhost ~]# tar -xzvf mysql-${VERSION}-el7-x86_64.tar.gz [root@localhost ~]# mv mysql-${VERSION}-el7-x86_64 /usr/local/ [root@localhost ~]# chown -R mysql:mysql /usr/local/mysql-${VERSION}-el7-x86_64 [root@localhost ~]# ls -l /usr/local/|grep mysql lrwxrwxrwx. 1 mysql mysql 34 Aug 26 23:05 mysql -> /usr/local/mysql-5.7.22-el7-x86_64 drwxr-xr-x. 9 mysql mysql 4096 Aug 26 23:02 mysql-5.7.22-el7-x86_64 drwxr-xr-x. 9 mysql mysql 4096 Aug 27 12:30 mysql-5.7.39-el7-x86_64 lrwxrwxrwx. 1 mysql mysql 44 Aug 27 00:04 mysql-shell -> mysql-shell-8.0.30-linux-glibc2.12-x86-64bit drwxr-xr-x. 6 mysql mysql 4096 Aug 27 00:02 mysql-shell-8.0.30-linux-glibc2.12-x86-64bit

3.2. 版本升级

3.2.1. 升级检查

参考 1.2 MySQL Shell 升级检查 完成升级前检查,及冲突项调整。

[mysql@localhost ~]$ export VERSION=5.7.39 [mysql@localhost ~]$ export VERSION=8.0.28 [mysql@localhost ~]$ export VERSION=8.0.30 [mysql@localhost ~]$ whereis mysqlsh mysqlsh: /usr/local/mysql-shell-8.0.30-linux-glibc2.12-x86-64bit/bin/mysqlsh [mysql@localhost ~]$ mysqlsh -- util checkForServerUpgrade root@192.168.3.227:5306 --target-version=${VERSION} --output-format=JSON --config-path=/etc/my.cnf

3.2.2. 备份数据库

参考 2 升级前备份,完成停机备份。

[mysql@localhost ~]$ mysql -u root -p --execute="SET GLOBAL innodb_fast_shutdown=0" [mysql@localhost ~]$ mysql -u root -p --execute="show GLOBAL variables like \"datadir%\"" Enter password: +---------------+------------------+ | Variable_name | Value | +---------------+------------------+ | datadir | /mysql/database/ | +---------------+------------------+ [mysql@localhost ~]$ sudo systemctl stop mysqld [mysql@localhost ~]$ tar -czvf /mysql/database_bak.tgz /mysql/database/

设置 innodb_fast_shutdown=0,将数据库关闭方式变更为慢关闭。在 MySQL 主要版本之间升级或降级之前使用 慢关闭 技术,以便在升级过程更新文件格式时做好所有数据文件的准备。

3.2.3. MySQL 软件升级

# 1. 更新 MySQL 软连接 [root@localhost ~]# export VERSION=5.7.39 [root@localhost ~]# export VERSION=8.0.28 [root@localhost ~]# export VERSION=8.0.30 [root@localhost ~]# ls -l /usr/local/|grep mysql [root@localhost ~]# rm /usr/local/mysql [root@localhost ~]# ln -s /usr/local/mysql-${VERSION}-el7-x86_64 /usr/local/mysql [root@localhost ~]# chown -R mysql:mysql /usr/local/mysql # 2. 检查权限 [root@localhost ~]# ls -l /usr/local/|grep mysql lrwxrwxrwx. 1 mysql mysql 34 Aug 27 12:37 mysql -> /usr/local/mysql-5.7.39-el7-x86_64 drwxr-xr-x. 9 mysql mysql 4096 Aug 26 23:02 mysql-5.7.22-el7-x86_64 drwxr-xr-x. 9 mysql mysql 4096 Aug 27 12:30 mysql-5.7.39-el7-x86_64 lrwxrwxrwx. 1 mysql mysql 44 Aug 27 00:04 mysql-shell -> mysql-shell-8.0.30-linux-glibc2.12-x86-64bit drwxr-xr-x. 6 mysql mysql 4096 Aug 27 00:02 mysql-shell-8.0.30-linux-glibc2.12-x86-64bit

3.2.4. 更新配置文件

[root@localhost ~]# ls -l /etc/my.cnf -rw-r--r--. 1 root root 2396 Aug 26 23:47 /etc/my.cnf [root@localhost ~]# cp /etc/my.cnf /etc/my.cnf.bak

根据 1.2.2 及 1.2.3 升级检查中,检测出的冲突项,调整配置文件 /etc/my.cnf

  1. 适用 5.7.x 配置文件
# 5.7.x 配置文件 [mysql@localhost ~]$ export MEMTOTAL=$(grep MemTotal /proc/meminfo|awk '{print $2}') [mysql@localhost ~]$ export INNODB_BUFFER=$(( MEMTOTAL * 1024 * 8 / 10 )) [mysql@localhost ~]$ echo ${INNODB_BUFFER} [mysql@localhost ~]$ cat /etc/my.cnf [mysqld] bind-address=0.0.0.0 port= 5306 user= mysql basedir=/usr/local/mysql datadir=/mysql/database/ socket=/mysql/socket/mysql.sock tmpdir=/mysql/mysql-tmp/ log-error=/mysql/mysql-log/mysql.err pid-file=/mysql/pid/mysql.pid default-authentication-plugin=mysql_native_password ### Server Config ### server-id= 100 autocommit = 1 character_set_server= utf8mb4 collation-server = utf8mb4_general_ci skip_name_resolve = 1 open_files_limit = 65535 max_connections = 3000 max_connect_errors = 100 interactive_timeout = 18800 wait_timeout = 18800 transaction_isolation = READ-COMMITTED explicit_defaults_for_timestamp = 1 sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO" table_open_cache = 4000 max_allowed_packet = 16M join_buffer_size = 128M tmp_table_size = 128M max_heap_table_size = 128M read_buffer_size = 16M read_rnd_buffer_size = 32M sort_buffer_size = 32M lower_case_table_names= 1 explicit_defaults_for_timestamp=true ### slow query config ### slow_query_log = on long_query_time = 600 slow_query_log_file =/mysql/mysql-log/slowquery.log ### binlog config ### #gtid_mode = on #enforce_gtid_consistency = on innodb-file-per-table = 1 #sync_binlog = 1 log-bin=/mysql/bin-log/mysql-bin binlog_format = row # binlog_expire_logs_seconds = 172800 # max_binlog_size = 1G binlog_ignore_db = mysql binlog_ignore_db = information_schema binlog_ignore_db = performation_schema binlog_ignore_db = sys ### innodb config ### innodb_log_files_in_group = 5 innodb_log_group_home_dir = /mysql/redo-log/ innodb_undo_directory = /mysql/undo-log/ #innodb_page_size = 16K # 0.8*Physical Memory for the dedicated MySQL Server,be equal to or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances innodb_buffer_pool_size = 2560M innodb_buffer_pool_instances = 20 innodb_log_file_size = 1G innodb_log_buffer_size = 100M #innodb_thread_concurrency = 64 [mysql] default-character-set=utf8mb4 socket=/mysql/socket/mysql.sock [client] default-character-set=utf8mb4 socket=/mysql/socket/mysql.sock ### client user config ### #host = localhost #user = root #password = 'syzx123' [mysqld_safe] socket=/mysql/socket/mysql.sock log-error=/mysql/mysql-log/mysql.err pid-file=/mysql/pid/mysql.pid
  1. 适用 8.0.x 配置文件
export MEMTOTAL=$(grep MemTotal /proc/meminfo|awk '{print $2}') export INNODB_BUFFER=$(( MEMTOTAL * 1024 * 8 / 10 )) echo ${INNODB_BUFFER} [mysql@localhost ~]$ cat > /etc/my.cnf << EOF [mysqld] bind-address=0.0.0.0 port= 5306 user= mysql basedir=/usr/local/mysql datadir=/mysql/database/ socket=/mysql/socket/mysql.sock tmpdir=/mysql/mysql-tmp/ log-error=/mysql/mysql-log/mysql.err pid-file=/mysql/pid/mysql.pid authentication_policy= mysql_native_password # MySQL 5.7 无此参数 ### Server Config ### server-id= 100 autocommit = 1 character_set_server= utf8mb4 collation-server = utf8mb4_general_ci skip_name_resolve = 1 open_files_limit = 65535 max_connections = 3000 max_connect_errors = 100 interactive_timeout = 18800 wait_timeout = 18800 transaction_isolation = READ-COMMITTED explicit_defaults_for_timestamp = 1 sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO" table_open_cache = 4000 max_allowed_packet = 16M join_buffer_size = 128M tmp_table_size = 128M max_heap_table_size = 128M read_buffer_size = 16M read_rnd_buffer_size = 32M sort_buffer_size = 32M lower_case_table_names= 1 explicit_defaults_for_timestamp=true ### slow query config ### slow_query_log = on long_query_time = 600 slow_query_log_file =/mysql/mysql-log/slowquery.log ### binlog config ### #gtid_mode = on #enforce_gtid_consistency = on innodb-file-per-table = 1 #sync_binlog = 1 log-bin=/mysql/bin-log/mysql-bin binlog_format = row binlog_expire_logs_seconds = 172800 max_binlog_size = 1G binlog_ignore_db = mysql binlog_ignore_db = information_schema binlog_ignore_db = performation_schema binlog_ignore_db = sys ### innodb config ### innodb_log_files_in_group = 5 innodb_log_group_home_dir = /mysql/redo-log/ innodb_undo_directory = /mysql/undo-log/ #innodb_page_size = 16K # 0.8*Physical Memory for the dedicated MySQL Server,be equal to or a multiple of innodb_buffer_pool_chunk_size * innodb_buffer_pool_instances innodb_buffer_pool_size = ${INNODB_BUFFER} innodb_buffer_pool_instances = 20 innodb_log_file_size = 1G innodb_log_buffer_size = 100M #innodb_thread_concurrency = 64 [mysql] default-character-set=utf8mb4 socket=/mysql/socket/mysql.sock [client] default-character-set=utf8mb4 socket=/mysql/socket/mysql.sock ### client user config ### #host = localhost #user = root #password = 'syzx123' [mysqld_safe] socket=/mysql/socket/mysql.sock log-error=/mysql/mysql-log/mysql.err pid-file=/mysql/pid/mysql.pid EOF

3.2.5. 启动新版数据库

  • 启动数据库
[mysql@localhost ~]$ whereis mysqld_safe mysqld_safe: /usr/local/mysql-5.7.39-el7-x86_64/bin/mysqld_safe [mysql@localhost ~]$ mysqld_safe --user=mysql --datadir=/mysql/database & [1] 5037
  • 查看启动日志
# 5.7.22 -> 5.7.39 [mysql@localhost ~]$ tail -f /mysql/mysql-log/mysql.err 2022-08-27T06:38:04.800235Z 0 [Warning] CA certificate ca.pem is self signed. 2022-08-27T06:38:04.800295Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory. 2022-08-27T06:38:04.800386Z 0 [Note] Server hostname (bind-address): '0.0.0.0'; port: 5306 2022-08-27T06:38:04.800405Z 0 [Note] - '0.0.0.0' resolves to '0.0.0.0'; 2022-08-27T06:38:04.800449Z 0 [Note] Server socket created on IP: '0.0.0.0'. 2022-08-27T06:38:04.804077Z 0 [Note] Failed to start slave threads for channel '' 2022-08-27T06:38:04.807186Z 0 [Warning] Optional native table 'performance_schema'.'processlist' has the wrong structure or is missing. 2022-08-27T06:38:04.807336Z 0 [Note] Event Scheduler: Loaded 0 events 2022-08-27T06:38:04.807532Z 0 [Note] /usr/local/mysql-5.7.39-el7-x86_64/bin/mysqld: ready for connections. Version: '5.7.39-log' socket: '/mysql/socket/mysql.sock' port: 5306 MySQL Community Server (GPL) # 5.7.39 -> 8.0.28 [mysql@localhost ~]$ tail -f /mysql/mysql-log/mysql.err 2022-08-27T09:11:49.072611Z mysqld_safe Logging to '/mysql/mysql-log/mysql.err'. 2022-08-27T09:11:49.097374Z mysqld_safe Starting mysqld daemon with databases from /mysql/database 2022-08-27T09:11:49.323913Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.30) starting as process 20988 2022-08-27T09:11:49.329516Z 0 [Warning] [MY-013907] [InnoDB] Deprecated configuration parameters innodb_log_file_size and/or innodb_log_files_in_group have been used to compute innodb_redo_log_capacity=5368709120. Please use innodb_redo_log_capacity instead. 2022-08-27T09:11:49.331022Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2022-08-27T09:11:49.777746Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2022-08-27T09:11:51.985112Z 4 [System] [MY-013381] [Server] Server upgrade from '80028' to '80030' started. 2022-08-27T09:11:56.709359Z 4 [System] [MY-013381] [Server] Server upgrade from '80028' to '80030' completed. 2022-08-27T09:11:56.836015Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2022-08-27T09:11:56.836056Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. 2022-08-27T09:11:56.855514Z 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: '8.0.30' socket: '/mysql/socket/mysql.sock' port: 5306 MySQL Community Server - GPL. 2022-08-27T09:11:56.855511Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /mysql/socket/mysqlx.sock # 8.0.28 -> 8.0.30 [mysql@localhost ~]$ tail -f /mysql/mysql-log/mysql.err 2022-08-27T09:11:49.072611Z mysqld_safe Logging to '/mysql/mysql-log/mysql.err'. 2022-08-27T09:11:49.097374Z mysqld_safe Starting mysqld daemon with databases from /mysql/database 2022-08-27T09:11:49.323913Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.30) starting as process 20988 2022-08-27T09:11:49.329516Z 0 [Warning] [MY-013907] [InnoDB] Deprecated configuration parameters innodb_log_file_size and/or innodb_log_files_in_group have been used to compute innodb_redo_log_capacity=5368709120. Please use innodb_redo_log_capacity instead. 2022-08-27T09:11:49.331022Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2022-08-27T09:11:49.777746Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2022-08-27T09:11:51.985112Z 4 [System] [MY-013381] [Server] Server upgrade from '80028' to '80030' started. 2022-08-27T09:11:56.709359Z 4 [System] [MY-013381] [Server] Server upgrade from '80028' to '80030' completed. 2022-08-27T09:11:56.836015Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2022-08-27T09:11:56.836056Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. 2022-08-27T09:11:56.855514Z 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: '8.0.30' socket: '/mysql/socket/mysql.sock' port: 5306 MySQL Community Server - GPL. 2022-08-27T09:11:56.855511Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /mysql/socket/mysqlx.sock

3.2.6. 系统库升级

低于 MySQL 8.0.16 的版本,需要执行 mysql_upgrade,以升级系统库(如 mysql):

[mysql@localhost ~]$ whereis mysql_upgrade mysql_upgrade: /usr/local/mysql-5.7.39-el7-x86_64/bin/mysql_upgrade [mysql@localhost ~]$ mysql_upgrade -u root -P 5306 -p Enter password: Checking if update is needed. Checking server version. Running queries to upgrade MySQL server. Checking system database. mysql.columns_priv OK mysql.db OK mysql.engine_cost OK mysql.event OK mysql.func OK mysql.general_log OK mysql.gtid_executed OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.innodb_index_stats OK mysql.innodb_table_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK mysql.server_cost OK mysql.servers OK mysql.slave_master_info OK mysql.slave_relay_log_info OK mysql.slave_worker_info OK mysql.slow_log OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK mysql.time_zone_name OK mysql.time_zone_transition OK mysql.time_zone_transition_type OK mysql.user OK Found outdated sys schema version 1.5.1. Upgrading the sys schema. Checking databases. sys.sys_config OK Upgrade process completed successfully. Checking if update is needed.

MySQL 8.0.16 及更高版本中,将 mysql_upgrade 客户端废弃。系统库(如 mysql 库)升级在启动服务进程启动时,根据需要自动完成。

3.3. 开机自启

重启数据库,以验证升级结果。

[mysql@localhost ~]$ mysqladmin -u root -p shutdown [mysql@localhost ~]$ ls /usr/local/mysql/support-files/ magic mysqld_multi.server mysql-log-rotate mysql.server [mysql@localhost ~]$ sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [mysql@localhost ~]$ sudo chmod +x /etc/init.d/mysqld [mysql@localhost ~]$ sudo vi /etc/init.d/mysqld # 修改 basedir 和 datadir .... # If you change base dir, you must also change datadir. These may get # overwritten by settings in the MySQL configuration files. basedir=/usr/local/mysql datadir=/mysql/database/ ....
[mysql@localhost ~]$ sudo chkconfig --add mysqld [mysql@localhost ~]$ sudo chkconfig --level 2345 mysqld on [mysql@localhost ~]$ sudo chkconfig --list

mysql 数据库启停测试(opsuser 操作):

[mysql@localhost ~]$ sudo systemctl start mysqld [mysql@localhost ~]$ sudo systemctl stop mysqld [mysql@localhost ~]$ sudo systemctl status mysqld [mysql@localhost ~]$ sudo systemctl enable mysqld # 开机自启 # 或 /etc/init.d/mysqld start /etc/init.d/mysqld stop /etc/init.d/mysqld start

登陆数据库,查看升级结果

[mysql@localhost ~]$ mysql -uroot -P5306 -p Enter password: Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select user,host from mysql.user; +---------------+---------------+ | user | host | +---------------+---------------+ | root | % | | system | % | | admin | 192.168.3.22_ | | mysql.session | localhost | | mysql.sys | localhost | +---------------+---------------+ 5 rows in set (0.00 sec)

3.4 主从架构的升级

MySQL 支持从低版本 MySQL 源库(即主库)复制到高版本 MySQL 的副本库(即从库),如 5.6 -> 5.75.7 -> 8.0。但不支持从高版本源库复制到低版本副本库。因此,在主从拓扑结构中,必须先将拓扑中的所有副本库(即从库)升级到目标 MySQL 版本,最后再升级主从复制拓扑中源库(即主库)的软件版本。

最后修改时间:2022-09-09 10:35:07
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论