在升级到最新的 MySQL 8.4 版本之前,请通过执行以下描述的初步检查来确保当前 MySQL 8.0 或 MySQL 8.4 服务器实例的升级准备就绪。否则,升级过程可能会失败。Before upgrading to the latest MySQL 8.4 release, ensure the upgrade readiness of your current MySQL 8.0 or MySQL 8.4 server instance by performing the preliminary checks described below. The upgrade process may fail otherwise.
可以考虑使用MySQL Shell 升级检查工具,该工具可以帮助您验证 MySQL 服务器实例是否准备好进行升级。您可以选择计划升级到的目标 MySQL 服务器版本,范围从 MySQL Server 8.0.11 到与当前 MySQL Shell 版本号匹配的 MySQL 服务器版本。升级检查工具会对指定的目标版本进行相关的自动检查,并提示您需要手动进行的其他相关检查。升级检查工具适用于 MySQL 的所有 Bugfix、Innovation 和 LTS 版本。MySQL Shell 的安装说明可以在这里找到。Consider using the MySQL Shell upgrade checker utility that enables you to verify whether MySQL server instances are ready for upgrade. You can select a target MySQL Server release to which you plan to upgrade, ranging from the MySQL Server 8.0.11 up to the MySQL Server release number that matches the current MySQL Shell release number. The upgrade checker utility carries out the automated checks that are relevant for the specified target release, and advises you of further relevant checks that you should make manually. The upgrade checker works for all Bugfix, Innovation, and LTS releases of MySQL. Installation instructions for MySQL Shell can be found here.
初步检查:Preliminary checks:
必须不存在以下问题:The following issues must not be present:
不得有使用过时数据类型或函数的表。There must be no tables that use obsolete data types or functions.
不得存在孤立的
.frm文件。There must be no orphan.frmfiles.触发器的创建者不得缺失或为空,也不得具有无效的创建上下文(由
character_set_client、collation_connection、Database Collation属性指示,这些属性可通过SHOW TRIGGERS或INFORMATION_SCHEMATRIGGERS表显示)。必须导出并恢复任何此类触发器以解决该问题。Triggers must not have a missing or empty definer or an invalid creation context (indicated by thecharacter_set_client,collation_connection,Database Collationattributes displayed bySHOW TRIGGERSor theINFORMATION_SCHEMATRIGGERStable). Any such triggers must be dumped and restored to fix the issue.
要检查这些问题,请执行此命令:To check for these issues, execute this command:
mysqlcheck -u root -p --all-databases --check-upgrade
如果 mysqlcheck 报告任何错误,请纠正这些问题。If mysqlcheck reports any errors, correct the issues.
不得有使用不支持原生分区的存储引擎的分区表。要识别此类表,请执行以下查询:There must be no partitioned tables that use a storage engine that does not have native partitioning support. To identify such tables, execute this query:
SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE ENGINE NOT IN ('innodb', 'ndbcluster') AND CREATE_OPTIONS LIKE '%partitioned%';查询报告的任何表都必须更改为使用
InnoDB,或者改为非分区表。要将表的存储引擎更改为InnoDB,请执行以下语句:Any table reported by the query must be altered to useInnoDBor be made nonpartitioned. To change a table storage engine toInnoDB, execute this statement:ALTER TABLE
table_nameENGINE = INNODB;有关将
MyISAM表转换为InnoDB的信息,请参见第 17.6.1.5 节,“将表从 MyISAM 转换为 InnoDB”。For information about convertingMyISAMtables toInnoDB, see Section 17.6.1.5, “Converting Tables from MyISAM to InnoDB”.要将分区表改为非分区表,请执行以下语句:To make a partitioned table nonpartitioned, execute this statement:
ALTER TABLE
table_nameREMOVE PARTITIONING;在 MySQL 8.4 中,一些关键字可能是保留字,而在以前版本中并非保留字。参见 第 11.3 节,“关键字和保留字”。这可能导致以前用作标识符的词变为非法。要修复受影响的语句,请使用标识符引用。参见 第 11.2 节,“模式对象名称”。Some keywords may be reserved in MySQL 8.4 that were not reserved previously. See Section 11.3, “Keywords and Reserved Words”. This can cause words previously used as identifiers to become illegal. To fix affected statements, use identifier quoting. See Section 11.2, “Schema Object Names”.
在 MySQL 8.3 的
mysql系统数据库中,不应存在与 MySQL 8.4 数据字典中使用的表同名的表。要识别具有这些名称的表,请执行此查询:There must be no tables in the MySQL 8.3mysqlsystem database that have the same name as a table used by the MySQL 8.4 data dictionary. To identify tables with those names, execute this query:SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE LOWER(TABLE_SCHEMA) = 'mysql' AND LOWER(TABLE_NAME) IN ( 'catalogs', 'character_sets', 'check_constraints', 'collations', 'column_statistics', 'column_type_elements', 'columns', 'dd_properties', 'events', 'foreign_key_column_usage', 'foreign_keys', 'index_column_usage', 'index_partitions', 'index_stats', 'indexes', 'parameter_type_elements', 'parameters', 'resource_groups', 'routines', 'schemata', 'st_spatial_reference_systems', 'table_partition_values', 'table_partitions', 'table_stats', 'tables', 'tablespace_files', 'tablespaces', 'triggers', 'view_routine_usage', 'view_table_usage' );查询中报告的任何表都必须被删除或重命名(使用
RENAME TABLE)。这也可能需要对使用受影响表的应用程序进行更改。Any tables reported by the query must be dropped or renamed (useRENAME TABLE). This may also entail changes to applications that use the affected tables.不能存在外键约束名称超过 64 个字符的表。使用此查询来识别约束名称过长的表:There must be no tables that have foreign key constraint names longer than 64 characters. Use this query to identify tables with constraint names that are too long:
SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME IN (SELECT LEFT(SUBSTR(ID,INSTR(ID,'/')+1), INSTR(SUBSTR(ID,INSTR(ID,'/')+1),'_ibfk_')-1) FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN WHERE LENGTH(SUBSTR(ID,INSTR(ID,'/')+1))>64);对于约束名称超过 64 个字符的表,先删除该约束,然后使用不超过 64 个字符的约束名称重新添加它(使用
ALTER TABLE)。For a table with a constraint name that exceeds 64 characters, drop the constraint and add it back with constraint name that does not exceed 64 characters (useALTER TABLE).sql_mode系统变量中不得定义任何过时的 SQL 模式。尝试使用过时的 SQL 模式会阻止 MySQL 8.4 启动。使用过时 SQL 模式的应用程序应进行修改以避免使用它们。有关 MySQL 8.4 中已移除的 SQL 模式的信息,请参见 服务器变更。There must be no obsolete SQL modes defined bysql_modesystem variable. Attempting to use an obsolete SQL mode prevents MySQL 8.4 from starting. Applications that use obsolete SQL modes should be revised to avoid them. For information about SQL modes removed in MySQL 8.4, see Server Changes.只升级已经正确关闭的 MySQL 服务器实例。如果实例意外关闭,则重启实例,并在升级前使用
innodb_fast_shutdown=0将其关闭。Only upgrade a MySQL server instance that was properly shut down. If the instance unexpectedly shutdown, then restart the instance and shut it down withinnodb_fast_shutdown=0before upgrade.不能存在带有明确定义的列名超过 64 个字符的视图(在 MySQL 5.7 中允许列名最多为 255 个字符的视图)。为了避免升级错误,应该在升级前修改此类视图。目前,识别列名超过 64 个字符的视图的唯一方法是使用
SHOW CREATE VIEW检查视图定义。您也可以通过查询信息模式VIEWS表来检查视图定义。There must be no views with explicitly defined columns names that exceed 64 characters (views with column names up to 255 characters were permitted in MySQL 5.7). To avoid upgrade errors, such views should be altered before upgrading. Currently, the only method of identify views with column names that exceed 64 characters is to inspect the view definition usingSHOW CREATE VIEW. You can also inspect view definitions by querying the Information SchemaVIEWStable.表或存储过程中不得有单个
ENUM或SET列元素超过 255 个字符或 1020 字节。在 MySQL 8.4 之前,ENUM或SET列元素的最大组合长度为 64K。在 MySQL 8.4 中,单个ENUM或SET列元素的最大字符长度为 255 个字符,最大字节长度为 1020 字节。(1020 字节的限制支持多字节字符集)在升级到 MySQL 8.0 之前,修改任何超过新限制的ENUM或SET列元素。否则,升级将因错误而失败。There must be no tables or stored procedures with individualENUMorSETcolumn elements that exceed 255 characters or 1020 bytes in length. Prior to MySQL 8.4, the maximum combined length ofENUMorSETcolumn elements was 64K. In MySQL 8.4, the maximum character length of an individualENUMorSETcolumn element is 255 characters, and the maximum byte length is 1020 bytes. (The 1020 byte limit supports multibyte character sets). Before upgrading to MySQL 8.0, modify anyENUMorSETcolumn elements that exceed the new limits. Failing to do so causes the upgrade to fail with an error.您的 MySQL 8.3 安装必须不使用 MySQL 8.4 不支持的功能。这里的任何更改都必然是安装特定的,但下面的例子说明了需要关注的内容类型:Your MySQL 8.3 installation must not use features that are not supported by MySQL 8.4. Any changes here are necessarily installation specific, but the following example illustrates the kind of thing to look for:
MySQL 8.4 中已移除了一些服务器启动选项和系统变量。请参阅 MySQL 8.4 中移除的功能,以及 第 1.5 节,“自 8.0 以来 MySQL 8.4 中添加、弃用或移除的服务器和状态变量及选项”。如果您使用了其中的任何内容,升级将需要进行配置更改。Some server startup options and system variables have been removed in MySQL 8.4. See Features Removed in MySQL 8.4, and Section 1.5, “Server and Status Variables and Options Added, Deprecated, or Removed in MySQL 8.4 since 8.0”. If you use any of these, an upgrade requires configuration changes.
如果您打算在升级时将
lower_case_table_names设置为 1,请确保在升级之前架构和表名都是小写。否则,由于架构或表名的字母大小写不匹配,可能会发生失败。您可以使用以下查询检查包含大写字母的架构和表名:If you intend to change thelower_case_table_namessetting to 1 at upgrade time, ensure that schema and table names are lowercase before upgrading. Otherwise, a failure could occur due to a schema or table name lettercase mismatch. You can use the following queries to check for schema and table names containing uppercase characters:mysql> select TABLE_NAME, if(sha(TABLE_NAME) !=sha(lower(TABLE_NAME)),'Yes','No') as UpperCase from information_schema.tables;如果
lower_case_table_names=1,升级过程会检查表名和架构名,以确保所有字符都是小写。如果发现表名或架构名包含大写字母,升级过程会因错误而失败。Iflower_case_table_names=1, table and schema names are checked by the upgrade process to ensure that all characters are lowercase. If table or schema names are found to contain uppercase characters, the upgrade process fails with an error.Note在升级时不建议更改
lower_case_table_names设置。Changing thelower_case_table_namessetting at upgrade time is not recommended.
如果由于上述任何问题导致升级到 MySQL 8.4 失败,服务器会将数据目录的所有更改恢复。在这种情况下,请删除所有重做日志文件并在现有数据目录上重新启动 MySQL 8.3 服务器以解决错误。重做日志文件(ib_logfile*)默认位于 MySQL 数据目录中。修复错误后,在再次尝试升级之前,先执行慢速关闭(通过设置 innodb_fast_shutdown=0)。If upgrade to MySQL 8.4 fails due to any of the
issues outlined above, the server reverts all changes to the data
directory. In this case, remove all redo log files and restart the
MySQL 8.3 server on the existing data directory to
address the errors. The redo log files
(ib_logfile*) reside in the MySQL data
directory by default. After the errors are fixed, perform a slow
shutdown (by setting
innodb_fast_shutdown=0) before
attempting the upgrade again.