8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 16 MySQL 数据字典 / 16.1 数据字典架构
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

16.1 数据字典架构16.1 Data Dictionary Schema

数据字典表是受保护的,只能在 MySQL 的调试版本中访问。然而,MySQL 支持通过 INFORMATION_SCHEMA 表和 SHOW 语句访问存储在数据字典表中的数据。有关组成数据字典的表的概述,请参见 数据字典表。Data dictionary tables are protected and may only be accessed in debug builds of MySQL. However, MySQL supports access to data stored in data dictionary tables through INFORMATION_SCHEMA tables and SHOW statements. For an overview of the tables that comprise the data dictionary, see Data Dictionary Tables.

MySQL 系统表在 MySQL 8.4 中仍然存在,可以通过在 mysql 系统数据库上执行 SHOW TABLES 语句来查看。通常,MySQL 数据字典表和系统表的区别在于,数据字典表包含执行 SQL 查询所需的元数据,而系统表包含辅助数据,如时区和帮助信息。MySQL 系统表和数据字典表在升级方式上也有所不同。MySQL 服务器管理数据字典的升级。参见 数据字典的升级方式。升级 MySQL 系统表需要运行完整的 MySQL 升级过程。参见 第 3.4 节,“MySQL 升级过程升级的内容”。MySQL system tables still exist in MySQL 8.4 and can be viewed by issuing a SHOW TABLES statement on the mysql system database. Generally, the difference between MySQL data dictionary tables and system tables is that data dictionary tables contain metadata required to execute SQL queries, whereas system tables contain auxiliary data such as time zone and help information. MySQL system tables and data dictionary tables also differ in how they are upgraded. The MySQL server manages data dictionary upgrades. See How the Data Dictionary is Upgraded. Upgrading MySQL system tables requires running the full MySQL upgrade procedure. See Section 3.4, “What the MySQL Upgrade Process Upgrades”.

数据字典的升级方式How the Data Dictionary is Upgraded

MySQL 的新版本可能会包含数据字典表定义的更改。此类更改存在于新安装的 MySQL 版本中,但在执行 MySQL 二进制文件的就地升级时,只有在使用新二进制文件重启 MySQL 服务器时,这些更改才会被应用。在启动时,服务器会将其数据字典版本与存储在数据字典中的版本信息进行比较,以确定是否需要升级数据字典表。如果需要升级且支持升级,服务器会使用更新后的定义创建数据字典表,将已持久化的元数据复制到新表中,原子性地将旧表替换为新表,并重新初始化数据字典。如果不需要升级,则启动会在不更新数据字典表的情况下继续进行。New versions of MySQL may include changes to data dictionary table definitions. Such changes are present in newly installed versions of MySQL, but when performing an in-place upgrade of MySQL binaries, changes are applied when the MySQL server is restarted using the new binaries. At startup, the data dictionary version of the server is compared to the version information stored in the data dictionary to determine if data dictionary tables should be upgraded. If an upgrade is necessary and supported, 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. If an upgrade is not necessary, startup continues without updating the data dictionary tables.

数据字典表的升级是一个原子操作,这意味着所有数据字典表都会根据需要升级,否则操作将失败。如果升级操作失败,服务器启动将因错误而失败。在这种情况下,可以使用旧的服务器二进制文件和旧的数据目录来启动服务器。当再次使用新的服务器二进制文件启动服务器时,会重新尝试数据字典的升级。Upgrade of data dictionary tables is an atomic operation, which means that all of the data dictionary tables are upgraded as necessary or the operation fails. If the upgrade operation fails, server startup fails with an error. In this case, the old server binaries can be used with the old data directory to start the server. When the new server binaries are used again to start the server, the data dictionary upgrade is reattempted.

通常,在数据字典表成功升级后,无法使用旧的服务器二进制文件重新启动服务器。因此,在数据字典表升级后,不支持将 MySQL 服务器二进制文件降级到之前的 MySQL 版本。Generally, after data dictionary tables are successfully upgraded, it is not possible to restart the server using the old server binaries. As a result, downgrading MySQL server binaries to a previous MySQL version is not supported after data dictionary tables are upgraded.

使用 MySQL 调试版本查看数据字典表Viewing Data Dictionary Tables Using a Debug Build of MySQL

数据字典表默认受保护,但可以通过编译带有调试支持的 MySQL(使用 -DWITH_DEBUG=1 CMake 选项)并指定 +d,skip_dd_table_access_check debug 选项和修饰符来访问。有关编译调试版本的信息,请参阅 第 7.9.1.1 节,“为调试编译 MySQL”。Data dictionary tables are protected by default but can be accessed by compiling MySQL with debugging support (using the -DWITH_DEBUG=1 CMake option) and specifying the +d,skip_dd_table_access_check debug option and modifier. For information about compiling debug builds, see Section 7.9.1.1, “Compiling MySQL for Debugging”.

Warning

不建议直接修改或写入数据字典表,这可能会导致您的 MySQL 实例无法操作。Modifying or writing to data dictionary tables directly is not recommended and may render your MySQL instance inoperable.

在使用调试支持编译 MySQL 后,使用此 SET 语句,使数据字典表对 mysql 客户端会话可见:After compiling MySQL with debugging support, use this SET statement to make data dictionary tables visible to the mysql client session:

mysql> SET SESSION debug='+d,skip_dd_table_access_check';

使用此查询检索数据字典表列表:Use this query to retrieve a list of data dictionary tables:

mysql> SELECT name, schema_id, hidden, type FROM mysql.tables where schema_id=1 AND hidden='System';

使用 SHOW CREATE TABLE 来查看数据字典表定义。例如:Use SHOW CREATE TABLE to view data dictionary table definitions. For example:

mysql> SHOW CREATE TABLE mysql.catalogs\G