前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >利用 mysqlsh 客户端检查升级 MySQL 8.0 兼容性

利用 mysqlsh 客户端检查升级 MySQL 8.0 兼容性

原创
作者头像
贺春旸的技术博客
发布2025-03-14 11:22:57
发布2025-03-14 11:22:57
1082
举报
文章被收录于专栏:DBA 平台和工具DBA 平台和工具

check-for-server-upgrade参数用于运行MySQL升级前检查工具,扫描当前数据库(版本5.7.42)与目标版本(8.0.41)的兼容性,识别潜在问题(如表损坏、字符集不兼容、保留关键字冲突、系统变量默认值变更等),并生成详细报告以指导用户在升级前修复或调整配置。

使用:

代码语言:bash
复制
./mysqlsh  -S /tmp/mysql_mysql57_1.sock -- util check-for-server-upgrade 
--config-path=/etc/my_57_1.cnf

输出:

代码语言:txt
复制
The MySQL server at /tmp%2Fmysql_mysql57_1.sock, version 5.7.42-log - MySQL
Community Server (GPL), will now be checked for compatibility issues for
upgrade to MySQL 8.0.41...

1) Usage of old temporal type
  No issues found

2) MySQL 8.0 syntax check for routine-like objects
  No issues found

3) Usage of db objects with names conflicting with new reserved keywords
  Warning: The following objects have names that conflict with new reserved
    keywords. Ensure queries sent by your applications use `quotes` when
    referring to them or they will result in errors.
  More information:
    https://dev.mysql.com/doc/refman/en/keywords.html

  test.reserved_demo.window - Column name

4) Usage of utf8mb3 charset
  Warning: The following objects use the utf8mb3 character set. It is
    recommended to convert them to use utf8mb4 instead, for improved Unicode
    support.
  More information:
    https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb3.html

  aa - schema's default character set: utf8
--More--ERROR: 2 errors were found. Please correct these issues before upgrading to avoid compatibility issues.
  cktest - schema's default character set: utf8
  drc - schema's default character set: utf8
  hcytest - schema's default character set: utf8
  percona - schema's default character set: utf8
  test - schema's default character set: utf8
  test1 - schema's default character set: utf8
  test2 - schema's default character set: utf8
  percona.checksums.db - column's default character set: utf8
  percona.checksums.tbl - column's default character set: utf8
  percona.checksums.chunk_index - column's default character set: utf8
  percona.checksums.lower_boundary - column's default character set: utf8
  percona.checksums.upper_boundary - column's default character set: utf8
  percona.checksums.this_crc - column's default character set: utf8
  percona.checksums.master_crc - column's default character set: utf8
  test.encrypted_data.salt - column's default character set: utf8
  test.products.product_name - column's default character set: utf8
  test.s.name - column's default character set: utf8
  test.sbtest1.c - column's default character set: utf8
  test.sbtest1.pad - column's default character set: utf8
  test.scores.student_name - column's default character set: utf8
  test.student.name - column's default character set: utf8
  test.student.course_ids - column's default character set: utf8
  test.students.name - column's default character set: utf8
  test.t1.info - column's default character set: utf8
  test.t2.name - column's default character set: utf8
  test.t2.address - column's default character set: utf8
  test.t8.address - column's default character set: utf8
  test.t9.name - column's default character set: utf8
  test.t9.city - column's default character set: utf8
  test.test_json.name - column's default character set: utf8
  test.test_no_pk.name - column's default character set: utf8
  test.user.name - column's default character set: utf8
  test2.A.name - column's default character set: utf8
  test2.t1.name - column's default character set: utf8
  test2.users.username - column's default character set: utf8
  test2.users.email - column's default character set: utf8

5) Table names in the mysql schema conflicting with new tables in 8.0
  No issues found

6) Partitioned tables using engines with non native partitioning
  No issues found

7) Foreign key constraint names longer than 64 characters
  No issues found

8) Usage of obsolete MAXDB sql_mode flag
  No issues found

9) Usage of obsolete sql_mode flags
  Notice: The following DB objects have obsolete options persisted for
    sql_mode, which will be cleared during upgrade to 8.0.
  More information:
    https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html#mysql-nutshell-removals

  test.insert_10000_records - PROCEDURE uses obsolete NO_AUTO_CREATE_USER
    sql_mode
  test.set_safe_updates_if_needed - PROCEDURE uses obsolete NO_AUTO_CREATE_USER
    sql_mode
  test.cleanup_expired_data - EVENT uses obsolete NO_AUTO_CREATE_USER sql_mode
  test2.trg_after_insert_A - TRIGGER uses obsolete NO_AUTO_CREATE_USER sql_mode
  test2.before_user_update - TRIGGER uses obsolete NO_AUTO_CREATE_USER sql_mode
  global system variable sql_mode - defined using obsolete NO_AUTO_CREATE_USER
    option

10) ENUM/SET column definitions containing elements longer than 255 characters
  No issues found

11) Usage of partitioned tables in shared tablespaces
  No issues found

12) Circular directory references in tablespace data file paths
  No issues found

13) Usage of removed functions
  No issues found

14) Usage of removed GROUP BY ASC/DESC syntax
  No issues found

15) Removed system variables for error logging to the system log configuration
  No issues found

16) Removed system variables
  No issues found

17) System variables with new default values
  Warning: Following system variables that are not defined in your
    configuration file will have new default values. Please review if you rely on
    their current values and if so define them before performing upgrade.
  More information:
    https://mysqlserverteam.com/new-defaults-in-mysql-8-0/

  back_log - default value will change
  collation_server - default value will change from latin1_swedish_ci to
    utf8mb4_0900_ai_ci
  event_scheduler - default value will change from OFF to ON
  explicit_defaults_for_timestamp - default value will change from OFF to ON
  innodb_autoinc_lock_mode - default value will change from 1 (consecutive) to
    2 (interleaved)
  innodb_flush_method - default value will change from NULL to fsync (Unix),
    unbuffered (Windows)
  innodb_flush_neighbors - default value will change from 1 (enable) to 0
    (disable)
  innodb_max_dirty_pages_pct - default value will change from 75 (%)  90 (%)
  innodb_max_dirty_pages_pct_lwm - default value will change from_0 (%) to 10
    (%)
  innodb_undo_log_truncate - default value will change from OFF to ON
  innodb_undo_tablespaces - default value will change from 0 to 2
  log_error_verbosity - default value will change from 3 (Notes) to 2 (Warning)
  max_allowed_packet - default value will change from 4194304 (4MB) to 67108864
    (64MB)
  max_error_count - default value will change from 64 to 1024
  optimizer_trace_max_mem_size - default value will change from 16KB to 1MB
  performance_schema_consumer_events_transactions_current - default value will
    change from OFF to ON
  performance_schema_consumer_events_transactions_history - default value will
    change from OFF to ON
  slave_rows_search_algorithms - default value will change from 'INDEX_SCAN,
    TABLE_SCAN' to 'INDEX_SCAN, HASH_SCAN'
  table_open_cache - default value will change from 2000 to 4000
  transaction_write_set_extraction - default value will change from OFF to
    XXHASH64

18) Zero Date, Datetime, and Timestamp values
  No issues found

19) Schema inconsistencies resulting from file removal or corruption
  Error: Following tables show signs that either table datadir directory or frm
    file was removed/corrupted. Please check server logs, examine datadir to
    detect the issue and fix it before upgrade

  test.#sql-157ae_c - present in INFORMATION_SCHEMA's INNODB_SYS_TABLES table
    but missing from TABLES table
  test.#sql-865c_3 - present in INFORMATION_SCHEMA's INNODB_SYS_TABLES table
    but missing from TABLES table

20) Tables recognized by InnoDB that belong to a different engine
  No issues found

21) Issues reported by 'check table x for upgrade' command
  No issues found

22) New default authentication plugin considerations
  Warning: The new default authentication plugin 'caching_sha2_password' offers
    more secure password hashing than previously used 'mysql_native_password'
    (and consequent improved client connection authentication). However, it also
    has compatibility implications that may affect existing MySQL installations. 
    If your MySQL installation must serve pre-8.0 clients and you encounter
    compatibility issues after upgrading, the simplest way to address those
    issues is to reconfigure the server to revert to the previous default
    authentication plugin (mysql_native_password). For example, use these lines
    in the server option file:
    
    [mysqld]
    default_authentication_plugin=mysql_native_password
    
    However, the setting should be viewed as temporary, not as a long term or
    permanent solution, because it causes new accounts created with the setting
    in effect to forego the improved authentication security.
    If you are using replication please take time to understand how the
    authentication plugin changes may impact you.
  More information:
    https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-compatibility-issues
    https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password-replication

23) Columns which cannot have default values
  No issues found

24) Check for invalid table names and schema names used in 5.7
  No issues found

25) Check for orphaned routines in 5.7
  No issues found

26) Check for deprecated usage of single dollar signs in object names
  No issues found

27) Check for indexes that are too large to work on higher versions of MySQL
Server than 5.7
  No issues found

28) Check for deprecated '.<table>' syntax used in routines.
  No issues found

29) Check for columns that have foreign keys pointing to tables from a diffrent
database engine.
  No issues found

Errors:   2
Warnings: 59
Notices:  6

这份报告通过mysqlsh util.checkForServerUpgrade()检查了MySQL服务器从5.7.42升级到8.0.41的兼容性,扫描了数据库对象、配置和系统变量等方面。结果显示:

  • 无问题项:大部分检查(如旧时间类型、移除的功能、分区表等)没有发现问题,可以直接升级。
  • 警告项:包括使用与新保留关键字冲突的列名、使用utf8mb3字符集、系统变量默认值变更等,需根据实际需求调整。
  • 通知项:主要是过时的sql_mode选项将在升级后被清除,可能影响部分存储过程或触发器。
  • 错误项:发现了2个严重问题,必须在升级前解决,否则会导致兼容性故障。

报错信息(Errors)

报告中明确指出2个错误,具体如下:

  1. 问题19: Schema inconsistencies resulting from file removal or corruption
    • 错误详情
      • 表 test.#sql-157ae_c 和 test.#sql-865c_3 在 INFORMATION_SCHEMA.INNODB_SYS_TABLES 中存在,但不在 TABLES 表中。
      • 这表明这些表的元数据文件(.frm文件)或数据目录(datadir)可能被删除或损坏。
    • 影响:升级前不修复会导致数据丢失或升级失败。
    • 解决建议
      1. 检查服务器日志,定位问题原因。
      2. 检查数据目录,确认文件是否存在。
      3. 如果是临时表,可删除: sql 收起取消自动换行复制 DROP TABLE test.`#sql-157ae_c`; DROP TABLE test.`#sql-865c_3`;
      4. 如果是重要表,需从备份恢复或修复。
  2. 报告总结中的提示
    • 内容: ERROR: 2 errors were found. Please correct these issues before upgrading to avoid compatibility issues.
    • 含义:明确指出有2个错误(即上述问题19),强调必须修复才能继续升级。

其他关键点(非报错,仅供参考)

  • 警告示例
    • 问题3:列名test.reserved_demo.window与MySQL 8.0新保留关键字冲突,需加反引号或重命名。
    • 问题4:多个数据库和列使用utf8mb3,建议转为utf8mb4。
    • 问题17:系统变量默认值变更,如collation_server从latin1_swedish_ci变为utf8mb4_0900_ai_ci,需检查配置。
  • 通知示例
    • 问题9:NO_AUTO_CREATE_USER选项已过时,升级后将被清除,影响部分存储过程和触发器。

总结

这份检查报告表明,你的MySQL 5.7.42服务器升级到8.0.41前,必须优先解决2个错误(表test.#sql-157ae_c和test.#sql-865c_3的文件损坏问题)。其他警告和通知可根据业务需求选择性处理。建议先备份数据,修复错误后再重新运行检查,确保升级顺利。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 使用:
  • 输出:
    • 报错信息(Errors)
    • 其他关键点(非报错,仅供参考)
  • 总结
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档