8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 3 升级 MySQL / 3.7 在 Unix/Linux 上升级 MySQL 二进制或基于包的安装
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

3.7 在 Unix/Linux 上升级 MySQL 二进制或基于包的安装3.7 Upgrading MySQL Binary or Package-based Installations on Unix/Linux

本节描述了如何在 Unix/Linux 上升级 MySQL 二进制和基于软件包的安装。介绍了就地升级和逻辑升级方法。This section describes how to upgrade MySQL binary and package-based installations on Unix/Linux. In-place and logical upgrade methods are described.

就地升级In-Place Upgrade

就地升级涉及关闭旧的 MySQL 服务器,用新的 MySQL 二进制文件或软件包替换旧的,然后在现有数据目录上重新启动 MySQL,并升级现有安装中需要升级的任何其他部分。有关可能需要升级的内容的详细信息,请参阅 第 3.4 节,“MySQL 升级过程升级的内容”。An in-place upgrade involves shutting down the old MySQL server, replacing the old MySQL binaries or packages with the new ones, restarting MySQL on the existing data directory, and upgrading any remaining parts of the existing installation that require upgrading. For details about what may need upgrading, see Section 3.4, “What the MySQL Upgrade Process Upgrades”.

Note

如果您正在升级最初通过安装多个 RPM 包创建的安装,请升级所有的包,而不仅仅是某些包。例如,如果您之前安装了服务器和客户端 RPM,请不要只升级服务器 RPM。If you are upgrading an installation originally produced by installing multiple RPM packages, upgrade all the packages, not just some. For example, if you previously installed the server and client RPMs, do not upgrade just the server RPM.

对于某些 Linux 平台,通过 RPM 或 Debian 包安装 MySQL 时,会包含用于管理 MySQL 服务器启动和关闭的 systemd 支持。在这些平台上,mysqld_safe 未安装。在这种情况下,请使用 systemd 来启动和关闭服务器,而不是使用以下说明中提到的方法。请参见 第 2.5.9 节,“使用 systemd 管理 MySQL 服务器”。For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. On these platforms, mysqld_safe is not installed. In such cases, use systemd for server startup and shutdown instead of the methods used in the following instructions. See Section 2.5.9, “Managing MySQL Server with systemd”.

对于 MySQL Cluster 的升级,也请参阅 MySQL Cluster 升级。For upgrades to MySQL Cluster installations, see also MySQL Cluster Upgrade.

要执行就地升级:To perform an in-place upgrade:

  1. 请查看 第 3.1 节,“开始之前” 中的信息。Review the information in Section 3.1, “Before You Begin”.

  2. 通过完成 第 3.6 节,“为升级准备安装” 中的初步检查,确保您的安装升级准备就绪。Ensure the upgrade readiness of your installation by completing the preliminary checks in Section 3.6, “Preparing Your Installation for Upgrade”.

  3. 如果您在使用 InnoDB 的同时使用 XA 事务,请在升级前运行 XA RECOVER 以检查未提交的 XA 事务。如果有返回结果,请通过发出 XA COMMIT 或 XA ROLLBACK 语句来提交或回滚 XA 事务。If you use XA transactions with InnoDB, run XA RECOVER before upgrading to check for uncommitted XA transactions. If results are returned, either commit or rollback the XA transactions by issuing an XA COMMIT or XA ROLLBACK statement.

  4. 如果您通常运行的 MySQL 服务器配置了 innodb_fast_shutdown 设置为 2(冷关闭),请通过执行以下任一语句将其配置为执行快速或慢速关闭:If you normally run your MySQL server configured with innodb_fast_shutdown set to 2 (cold shutdown), configure it to perform a fast or slow shutdown by executing either of these statements:

    SET GLOBAL innodb_fast_shutdown = 1; -- fast shutdown
    SET GLOBAL innodb_fast_shutdown = 0; -- slow shutdown
    

    使用快速或慢速关闭时,InnoDB 会将其撤销日志和数据文件保留在一种可处理的状态,以应对不同版本之间的文件格式差异。With a fast or slow shutdown, InnoDB leaves its undo logs and data files in a state that can be dealt with in case of file format differences between releases.

  5. 关闭旧的 MySQL 服务器。例如:Shut down the old MySQL server. For example:

    mysqladmin -u root -p shutdown
    
  6. 升级 MySQL 二进制文件或软件包。如果是升级二进制安装,请解压新的 MySQL 二进制分发包。请参阅 获取并解压分发包。对于基于软件包的安装,请安装新的软件包。Upgrade the MySQL binaries or packages. If upgrading a binary installation, unpack the new MySQL binary distribution package. See Obtain and Unpack the Distribution. For package-based installations, install the new packages.

  7. 使用现有的数据目录启动 MySQL 8.4 服务器。例如:Start the MySQL 8.4 server, using the existing data directory. For example:

    mysqld_safe --user=mysql --datadir=/path/to/existing-datadir &
    

    如果存在加密的 InnoDB 表空间,请使用 --early-plugin-load 选项来加载密钥环插件。If there are encrypted InnoDB tablespaces, use the --early-plugin-load option to load the keyring plugin.

    当您启动 MySQL 8.4 服务器时,它会自动检测数据字典表是否存在。如果不存在,服务器会在数据目录中创建这些表,用元数据填充它们,然后继续其正常启动序列。在此过程中,服务器会升级所有数据库对象的元数据,包括数据库、表空间、系统和用户表、视图以及存储程序(存储过程和函数、触发器以及事件调度器事件)。服务器还会删除以前用于存储元数据的文件。例如,在从 MySQL 8.3 升级到 MySQL 8.4 之后,您可能会注意到表不再有 .frm 文件。When you start the MySQL 8.4 server, it automatically detects whether data dictionary tables are present. If not, the server creates them in the data directory, populates them with metadata, and then proceeds with its normal startup sequence. During this process, the server upgrades metadata for all database objects, including databases, tablespaces, system and user tables, views, and stored programs (stored procedures and functions, triggers, and Event Scheduler events). The server also removes files that previously were used for metadata storage. For example, after upgrading from MySQL 8.3 to MySQL 8.4, you may notice that tables no longer have .frm files.

    如果此步骤失败,服务器会将数据目录的所有更改恢复。在这种情况下,你应该删除所有重做日志文件,在相同的数据目录上启动你的 MySQL 8.3 服务器,并修复任何错误的原因。然后对 8.3 服务器执行另一次慢关闭,并启动 MySQL 8.4 服务器再次尝试。If this step fails, the server reverts all changes to the data directory. In this case, you should remove all redo log files, start your MySQL 8.3 server on the same data directory, and fix the cause of any errors. Then perform another slow shutdown of the 8.3 server and start the MySQL 8.4 server to try again.

  8. 在上一步中,服务器根据需要升级数据字典,对 mysql 系统数据库在 MySQL 8.3 和 MySQL 8.4 之间进行必要的更改,这样您就可以利用新的权限或功能。它还会将 Performance Schema、INFORMATION_SCHEMA 和 sys 数据库更新到 MySQL 8.4,并检查所有用户数据库是否与当前版本的 MySQL 不兼容。In the previous step, the server upgrades the data dictionary as necessary, making any changes required in the mysql system database between MySQL 8.3 and MySQL 8.4, so that you can take advantage of new privileges or capabilities. It also brings the Performance Schema, INFORMATION_SCHEMA, and sys databases up to date for MySQL 8.4, and examines all user databases for incompatibilities with the current version of MySQL.

Note

升级过程不会升级时区表的内容。有关升级说明,请参见 第 7.1.15 节,“MySQL 服务器时区支持”。The upgrade process does not upgrade the contents of the time zone tables. For upgrade instructions, see Section 7.1.15, “MySQL Server Time Zone Support”.

逻辑升级Logical Upgrade

逻辑升级包括使用备份或导出工具(如 mysqldump)从旧的 MySQL 实例导出 SQL,安装新的 MySQL 服务器,然后将 SQL 应用到新的 MySQL 实例。有关可能需要升级的内容的详细信息,请参阅 第 3.4 节,“MySQL 升级过程升级的内容”。A logical upgrade involves exporting SQL from the old MySQL instance using a backup or export utility such as mysqldump, installing the new MySQL server, and applying the SQL to your new MySQL instance. For details about what may need upgrading, see Section 3.4, “What the MySQL Upgrade Process Upgrades”.

Note

对于某些 Linux 平台,通过 RPM 或 Debian 包安装 MySQL 时,会包含用于管理 MySQL 服务器启动和关闭的 systemd 支持。在这些平台上,mysqld_safe 未安装。在这种情况下,请使用 systemd 来启动和关闭服务器,而不是使用以下说明中提到的方法。请参见 第 2.5.9 节,“使用 systemd 管理 MySQL 服务器”。For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. On these platforms, mysqld_safe is not installed. In such cases, use systemd for server startup and shutdown instead of the methods used in the following instructions. See Section 2.5.9, “Managing MySQL Server with systemd”.

Warning

将从以前的 MySQL 版本提取的 SQL 应用于新的 MySQL 版本可能会由于新功能、已更改功能、已弃用功能或已移除功能所引入的不兼容性而导致错误。因此,从以前的 MySQL 版本提取的 SQL 可能需要修改以实现逻辑升级。Applying SQL extracted from a previous MySQL release to a new MySQL release may result in errors due to incompatibilities introduced by new, changed, deprecated, or removed features and capabilities. Consequently, SQL extracted from a previous MySQL release may require modification to enable a logical upgrade.

要在升级到最新的 MySQL 8.4 版本之前识别不兼容问题,请执行第 3.6 节,“为升级准备您的安装”中描述的步骤。To identify incompatibilities before upgrading to the latest MySQL 8.4 release, perform the steps described in Section 3.6, “Preparing Your Installation for Upgrade”.

要执行逻辑升级:To perform a logical upgrade:

  1. 请查看 第 3.1 节,“开始之前” 中的信息。Review the information in Section 3.1, “Before You Begin”.

  2. 从先前的 MySQL 安装中导出现有数据:Export your existing data from the previous MySQL installation:

    mysqldump -u root -p
      --add-drop-table --routines --events
      --all-databases --force > data-for-upgrade.sql
    
    Note

    如果您的数据库包含存储程序,请在使用 mysqldump 时使用 --routines 和 --events 选项(如上所示)。--all-databases 选项会在转储中包含所有数据库,包括存放系统表的 mysql 数据库。Use the --routines and --events options with mysqldump (as shown above) if your databases include stored programs. The --all-databases option includes all databases in the dump, including the mysql database that holds the system tables.

    Important

    如果您的表包含生成列,请使用 MySQL 5.7.9 或更高版本提供的 mysqldump 工具来创建转储文件。早期版本提供的 mysqldump 工具在生成列定义中使用了不正确的语法(Bug #20769542)。您可以使用信息模式 COLUMNS 表来识别包含生成列的表。If you have tables that contain generated columns, use the mysqldump utility provided with MySQL 5.7.9 or higher to create your dump files. The mysqldump utility provided in earlier releases uses incorrect syntax for generated column definitions (Bug #20769542). You can use the Information Schema COLUMNS table to identify tables with generated columns.

  3. 关闭旧的 MySQL 服务器。例如:Shut down the old MySQL server. For example:

    mysqladmin -u root -p shutdown
    
  4. 安装 MySQL 8.4。有关安装说明,请参见 第 2 章,安装 MySQL。Install MySQL 8.4. For installation instructions, see Chapter 2, Installing MySQL.

  5. 初始化一个新的数据目录,如第 2.9.1 节,“初始化数据目录”所述。例如:Initialize a new data directory, as described in Section 2.9.1, “Initializing the Data Directory”. For example:

    mysqld --initialize --datadir=/path/to/8.4-datadir
         

    复制显示在屏幕上或写入错误日志的临时 'root'@'localhost' 密码以备后用。Copy the temporary 'root'@'localhost' password displayed to your screen or written to your error log for later use.

  6. 使用新的数据目录启动 MySQL 8.4 服务器。例如:Start the MySQL 8.4 server, using the new data directory. For example:

    mysqld_safe --user=mysql --datadir=/path/to/8.4-datadir &
    
  7. 重置 root 密码:Reset the root password:

    $> mysql -u root -p
    Enter password: ****  <- enter temporary root password
    
    mysql> ALTER USER USER() IDENTIFIED BY 'your new password';
         
  8. 将先前创建的转储文件加载到新的 MySQL 服务器中。例如:Load the previously created dump file into the new MySQL server. For example:

    mysql -u root -p --force < data-for-upgrade.sql
    
    Note

    当服务器启用了 GTID(gtid_mode=ON)时,如果你的导出文件包含系统表,不推荐加载该导出文件。mysqldump 对使用非事务型 MyISAM 存储引擎的系统表发出 DML 指令,而在启用 GTID 时这种组合是不允许的。还要注意,将一个启用 GTID 的服务器导出的文件加载到另一个同样启用 GTID 的服务器时,会生成不同的事务标识符。It is not recommended to load a dump file when GTIDs are enabled on the server (gtid_mode=ON), if your dump file includes system tables. mysqldump issues DML instructions for the system tables which use the non-transactional MyISAM storage engine, and this combination is not permitted when GTIDs are enabled. Also be aware that loading a dump file from a server with GTIDs enabled, into another server with GTIDs enabled, causes different transaction identifiers to be generated.

  9. 执行任何剩余的升级操作:Perform any remaining upgrade operations:

    关闭服务器,然后使用 --upgrade=FORCE 选项重新启动服务器,以执行剩余的升级任务:Shut down the server, then restart it with the --upgrade=FORCE option to perform the remaining upgrade tasks:

    mysqladmin -u root -p shutdown
    mysqld_safe --user=mysql --datadir=/path/to/8.4-datadir --upgrade=FORCE &
    

    使用 --upgrade=FORCE 重启后,服务器会对 MySQL 8.3 和 MySQL 8.4 之间 mysql 系统架构所需进行的任何更改,以便您可以利用新的权限或功能。它还会将 Performance Schema、INFORMATION_SCHEMA 和 sys 架构更新到 MySQL 8.4,并检查所有用户架构是否与当前版本的 MySQL 存在不兼容之处。Upon restart with --upgrade=FORCE, the server makes any changes required in the mysql system schema between MySQL 8.3 and MySQL 8.4, so that you can take advantage of new privileges or capabilities. It also brings the Performance Schema, INFORMATION_SCHEMA, and sys schema up to date for MySQL 8.4, and examines all user schemas for incompatibilities with the current version of MySQL.

Note

升级过程不会升级时区表的内容。有关升级说明,请参见 第 7.1.15 节,“MySQL 服务器时区支持”。The upgrade process does not upgrade the contents of the time zone tables. For upgrade instructions, see Section 7.1.15, “MySQL Server Time Zone Support”.

MySQL 集群升级MySQL Cluster Upgrade

本节中的信息是对就地升级中描述的就地升级程序的补充,用于在您升级 MySQL 集群时使用。The information in this section is an adjunct to the in-place upgrade procedure described in In-Place Upgrade, for use if you are upgrading MySQL Cluster.

MySQL 集群升级可以作为常规的滚动升级进行,按照通常的三个有序步骤:A MySQL Cluster upgrade can be performed as a regular rolling upgrade, following the usual three ordered steps:

  1. 升级 MGM 节点。Upgrade MGM nodes.

  2. 逐个升级数据节点。Upgrade data nodes one at a time.

  3. 逐个升级 API 节点(包括 MySQL 服务器)。Upgrade API nodes one at a time (including MySQL servers).

升级每个单独的 mysqld 有两个步骤:There are two steps to upgrading each individual mysqld:

  1. 导入数据字典。Import the data dictionary.

    使用 --upgrade=MINIMAL 选项启动新的服务器,以升级数据字典但不升级系统表。Start the new server with the --upgrade=MINIMAL option to upgrade the data dictionary but not the system tables.

    MySQL 服务器必须连接到 NDB 才能完成此阶段。如果存在任何 NDB 或 NDBINFO 表,并且服务器无法连接到集群,则会以错误信息退出:The MySQL server must be connected to NDB for this phase to complete. If any NDB or NDBINFO tables exist, and the server cannot connect to the cluster, it exits with an error message:

    Failed to Populate DD tables.
    
  2. 通过重新启动每个单独的 mysqld 来升级系统表,且不使用 --upgrade=MINIMAL 选项。Upgrade the system tables by restarting each individual mysqld without the --upgrade=MINIMAL option.