14.1 Data Dictionary Schema数据字典架构

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

MySQL system tables still exist in MySQL 8.0 and can be viewed by issuing a SHOW TABLES statement on the mysql system database. MySQL系统表仍然存在于MySQL 8.0中,可以通过在MySQL系统数据库上发出SHOW tables语句来查看。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数据字典表和系统表之间的区别在于,数据字典表包含执行SQL查询所需的元数据,而系统表包含时区和帮助信息等辅助数据。MySQL system tables and data dictionary tables also differ in how they are upgraded. MySQL系统表和数据字典表在升级方式上也有所不同。The MySQL server manages data dictionary upgrades. MySQL服务器管理数据字典升级。SQL server. See How the Data Dictionary is Upgraded. 查看如何升级数据字典Upgrading MySQL system tables requires running the full MySQL upgrade procedure. 升级MySQL系统表需要运行完整的MySQL升级过程。See Section 2.11.3, “What the MySQL Upgrade Process Upgrades”.请参阅第2.11.3节,“MySQL升级过程升级的内容”

How the Data Dictionary is Upgraded如何升级数据字典

New versions of MySQL may include changes to data dictionary table definitions. MySQL的新版本可能包括对数据字典表定义的更改。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. 这些更改出现在新安装的MySQL版本中,但在执行MySQL二进制文件的就地升级时,使用新二进制文件重新启动MySQL服务器时会应用这些更改。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.当新的服务器二进制文件再次用于启动服务器时,将重新尝试数据字典升级。

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服务器二进制文件降级到以前的MySQL版本。

The mysqld --no-dd-upgrade option can be used to prevent automatic upgrade of data dictionary tables at startup. mysqld --no-dd-upgrade选项可用于防止在启动时自动升级数据字典表。When --no-dd-upgrade is specified, and the server finds that the data dictionary version of the server is different from the version stored in the data dictionary, startup fails with an error stating that the data dictionary upgrade is prohibited.如果未指定--no-dd-upgrade,并且服务器发现服务器的数据字典版本与存储在数据字典中的版本不同,则启动失败,并出现一个错误,表明数据字典升级被禁止。

Viewing Data Dictionary Tables Using a Debug Build of MySQL使用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. 默认情况下,数据字典表受到保护,但可以通过编译支持调试的MySQL(使用-DWITH_DEBUG=1 CMake选项)并指定+d,skip_dd_table_access_check选项和DEBUG修饰符来访问。For information about compiling debug builds, see Section 5.9.1.1, “Compiling MySQL for Debugging”.有关编译调试版本的信息,请参阅第5.9.1.1节,“编译MySQL进行调试”

Warning警告

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

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

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';

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

mysql> SHOW CREATE TABLE mysql.catalogs\G