8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 3 升级 MySQL / 3.4 MySQL 升级过程升级什么
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

3.4 MySQL 升级过程升级的内容3.4 What the MySQL Upgrade Process Upgrades

安装新的 MySQL 版本可能需要升级现有安装的以下部分:Installing a new version of MySQL may require upgrading these parts of the existing installation:

  • mysql 系统模式,其中包含在 MySQL 服务器运行时所需的表信息(参见 第 7.3 节,“mysql 系统模式”)。mysql 模式表大致分为两类:The mysql system schema, which contains tables that store information required by the MySQL server as it runs (see Section 7.3, “The mysql System Schema”). mysql schema tables fall into two broad categories:

    • 数据字典表,用于存储数据库对象的元数据。Data dictionary tables, which store database object metadata.

    • 系统表(即剩余的非数据字典表),用于其他操作用途。System tables (that is, the remaining non-data dictionary tables), which are used for other operational purposes.

  • ,其中一些是内置的,可能被视为“服务器拥有”,另一些则不是:Other schemas, some of which are built in and may be considered “owned” by the server, and others which are not:

安装的某些部分可能需要升级,这些部分关联有两个不同的版本号:Two distinct version numbers are associated with parts of the installation that may require upgrading:

  • 数据字典版本。这适用于数据字典表。The data dictionary version. This applies to the data dictionary tables.

  • 服务器版本,也称为 MySQL 版本。这适用于系统表和其他模式中的对象。The server version, also known as the MySQL version. This applies to the system tables and objects in other schemas.

在这两种情况下,适用于现有 MySQL 安装的实际版本存储在数据字典中,而当前的期望版本已编译到新版本的 MySQL 中。当实际版本低于当前期望版本时,与该版本关联的安装部分必须升级到当前版本。如果两个版本都显示需要升级,则必须先进行数据字典升级。In both cases, the actual version applicable to the existing MySQL installation is stored in the data dictionary, and the current expected version is compiled into the new version of MySQL. When an actual version is lower than the current expected version, those parts of the installation associated with that version must be upgraded to the current version. If both versions indicate an upgrade is needed, the data dictionary upgrade must occur first.

作为前面提到的两种不同版本的反映,升级分为两个步骤:As a reflection of the two distinct versions just mentioned, the upgrade occurs in two steps:

  • 步骤 1:数据字典升级。Step 1: Data dictionary upgrade.

    此步骤升级:This step upgrades:

    • mysql 架构中的数据字典表。如果实际数据字典版本低于当前预期版本,服务器会创建具有更新定义的数据字典表,将已保存的元数据复制到新表中,原子性地用新表替换旧表,并重新初始化数据字典。The data dictionary tables in the mysql schema. If the actual data dictionary version is lower than the current expected version, the server creates data dictionary tables with updated definitions, copies persisted metadata to the new tables, atomically replaces the old tables with the new ones, and reinitializes the data dictionary.

    • 性能模式(Performance Schema)、INFORMATION_SCHEMA 和 ndbinfo。The Performance Schema, INFORMATION_SCHEMA, and ndbinfo.

  • 步骤 2:服务器升级。Step 2: Server upgrade.

    此步骤包括所有其他升级任务。如果现有 MySQL 安装的服务器版本低于新安装的 MySQL 版本,则必须升级其他所有内容:This step comprises all other upgrade tasks. If the server version of the existing MySQL installation is lower than that of the new installed MySQL version, everything else must be upgraded:

    • mysql 模式中的系统表(其余非数据字典表)。The system tables in the mysql schema (the remaining non-data dictionary tables).

    • sys 模式。The sys schema.

    • 用户模式。User schemas.

数据字典升级(步骤 1)是服务器的责任,服务器在启动时会根据需要执行此任务,除非使用阻止其执行的选项调用。该选项是 --upgrade=NONE。The data dictionary upgrade (step 1) is the responsibility of the server, which performs this task as necessary at startup unless invoked with an option that prevents it from doing so. The option is --upgrade=NONE.

如果数据字典已过期,但服务器被阻止进行升级,服务器将无法运行,并且会以错误退出。例如:If the data dictionary is out of date but the server is prevented from upgrading it, the server does not run, and exits with an error instead. For example:

[ERROR] [MY-013381] [Server] Server shutting down because upgrade is
required, yet prohibited by the command line option '--upgrade=NONE'.
[ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
[ERROR] [MY-010020] [Server] Data Dictionary initialization failed.

--upgrade 服务器选项控制服务器在启动时是否以及如何执行自动升级:The --upgrade server option controls whether and how the server performs an automatic upgrade at startup:

  • 如果没有指定该选项或使用 --upgrade=AUTO,服务器将升级其认为已过期的任何内容(步骤 1 和 2)。With no option or with --upgrade=AUTO, the server upgrades anything it determines to be out of date (steps 1 and 2).

  • 使用 --upgrade=NONE 时,服务器不会升级任何内容(跳过步骤 1 和 2),但如果必须升级数据字典,则也会以错误退出。无法在数据字典过时的情况下运行服务器;服务器坚持要么升级它,要么退出。With --upgrade=NONE, the server upgrades nothing (skips steps 1 and 2), but also exits with an error if the data dictionary must be upgraded. It is not possible to run the server with an out-of-date data dictionary; the server insists on either upgrading it or exiting.

  • 使用 --upgrade=MINIMAL,服务器会在必要时升级数据字典、性能模式(Performance Schema)和 INFORMATION_SCHEMA(步骤 1)。请注意,使用此选项升级后,无法启动组复制(Group Replication),因为复制内部依赖的系统表尚未更新,并且其他区域可能也会出现功能受限的情况。With --upgrade=MINIMAL, the server upgrades the data dictionary, the Performance Schema, and the INFORMATION_SCHEMA, if necessary (step 1). Note that following an upgrade with this option, Group Replication cannot be started, because system tables on which the replication internals depend are not updated, and reduced functionality might also be apparent in other areas.

  • 使用 --upgrade=FORCE 时,服务器会在必要时升级数据字典、性能模式 (Performance Schema) 和 INFORMATION_SCHEMA(步骤 1),并强制升级其他所有内容(步骤 2)。使用此选项时,服务器启动预计会更慢,因为服务器会检查所有模式中的所有对象。With --upgrade=FORCE, the server upgrades the data dictionary, the Performance Schema, and the INFORMATION_SCHEMA, if necessary (step 1), and forces an upgrade of everything else (step 2). Expect server startup to take longer with this option because the server checks all objects in all schemas.

FORCE 在服务器认为某些操作不必要时,仍然可以强制执行步骤 2 的操作。FORCE 与 AUTO 的一个区别在于,使用 FORCE 时,如果系统表(如帮助表或时区表)缺失,服务器会重新创建这些表。FORCE is useful to force step 2 actions to be performed if the server thinks they are not necessary. One way that FORCE differs from AUTO is that with FORCE, the server re-creates system tables such as help tables or time zone tables if they are missing.

关于升级步骤 2 期间发生情况的附加说明:Additional notes about what occurs during upgrade step 2:

  • 步骤 2 会在未安装 sys 模式时安装它,否则会将其升级到当前版本。如果存在 sys 模式但没有 version 视图,则会发生错误,因为假定其缺失表示这是用户创建的模式:Step 2 installs the sys schema if it is not installed, and upgrades it to the current version otherwise. An error occurs if a sys schema exists but has no version view, on the assumption that its absence indicates a user-created schema:

    A sys schema exists with no sys.version view. If
    you have a user created sys schema, this must be renamed for the
    upgrade to succeed.
    

    在这种情况下进行升级,请先删除或重命名现有的 sys 模式。然后再次执行升级程序。(可能需要强制执行步骤 2。)To upgrade in this case, remove or rename the existing sys schema first. Then perform the upgrade procedure again. (It may be necessary to force step 2.)

    要防止 sys 模式检查,请使用 --upgrade=NONE 或 --upgrade=MINIMAL 选项启动服务器。To prevent the sys schema check, start the server with the --upgrade=NONE or --upgrade=MINIMAL option.

  • 第 2 步升级系统表以确保它们具有当前结构,这包括帮助表,但不包括时区表。加载时区表的过程依赖于平台,并且需要 DBA 进行决策,因此无法自动完成。Step 2 upgrades the system tables to ensure that they have the current structure, and this includes the help tables but not the time zone tables. The procedure for loading time zone tables is platform dependent and requires decision making by the DBA, so it cannot be done automatically.

  • 当步骤 2 升级 mysql 模式下的系统表时,mysql.db、mysql.tables_priv、mysql.columns_priv 和 mysql.procs_priv 表的主键列顺序会更改,以将主机名和用户名列放在一起。将主机名和用户名放在一起意味着可以使用索引查找,这提高了 CREATE USER、DROP USER 以及 RENAME USER 语句的性能,以及在多个用户拥有多重权限时的 ACL 检查。删除并重新创建索引是必要的,如果系统中有大量用户和权限,这可能会花费一些时间。When Step 2 is upgrading the system tables in the mysql schema, the column order in the primary key of the mysql.db, mysql.tables_priv, mysql.columns_priv and mysql.procs_priv tables is changed to place the host name and user name columns together. Placing the host name and user name together means that index lookup can be used, which improves performance for CREATE USER, DROP USER, and RENAME USER statements, and for ACL checks for multiple users with multiple privileges. Dropping and re-creating the index is necessary and might take some time if the system has a large number of users and privileges.

  • 步骤 2 根据需要处理所有用户模式中的所有表。表检查可能需要较长时间完成。每个表都被锁定,因此在处理过程中对其他会话不可用。检查和修复操作可能耗时,尤其是对于大型表。表检查使用FOR UPGRADE option of the CHECK TABLE语句选项。关于该选项的具体内容,请参见第 15.7.3.2 节,“CHECK TABLE 语句”.Step 2 processes all tables in all user schemas as necessary. Table checking might take a long time to complete. Each table is locked and therefore unavailable to other sessions while it is being processed. Check and repair operations can be time-consuming, particularly for large tables. Table checking uses the FOR UPGRADE option of the CHECK TABLE statement. For details about what this option entails, see Section 15.7.3.2, “CHECK TABLE Statement”.

    为了防止表检查,请使用 --upgrade=NONE 或 --upgrade=MINIMAL 选项启动服务器。To prevent table checking, start the server with the --upgrade=NONE or --upgrade=MINIMAL option.

    为了强制表检查,请使用 --upgrade=FORCE 选项启动服务器。To force table checking, start the server with the --upgrade=FORCE option.

  • 步骤 2 会用当前的 MySQL 版本号标记所有已检查和修复的表。这确保了下次使用相同版本的服务器进行升级检查时,可以确定是否需要再次检查或修复某个表。Step 2 marks all checked and repaired tables with the current MySQL version number. This ensures that the next time upgrade checking occurs with the same version of the server, it can be determined whether there is any need to check or repair a given table again.