5.3 The mysql System Schemamysql系统模式

The mysql schema is the system schema. mysql模式是系统模式。It contains tables that store information required by the MySQL server as it runs. 它包含存储MySQL服务器运行时所需信息的表。A broad categorization is that the mysql schema contains data dictionary tables that store database object metadata, and system tables used for other operational purposes. 一个广泛的分类是,mysql模式包含存储数据库对象元数据的数据字典表,以及用于其他操作目的的系统表。The following discussion further subdivides the set of system tables into smaller categories.下面的讨论将系统表集进一步细分为更小的类别。

The remainder of this section enumerates the tables in each category, with cross references for additional information. Data dictionary tables and system tables use the InnoDB storage engine unless otherwise indicated.本节的其余部分列举了每个类别中的表,并提供了其他信息的交叉引用。除非另有说明,否则数据字典表和系统表使用InnoDB存储引擎。

mysql system tables and data dictionary tables reside in a single InnoDB tablespace file named mysql.ibd in the MySQL data directory. mysql系统表和数据字典表位于mysql数据目录中一个名为mysql.ibdInnoDB表空间文件中。Previously, these tables were created in individual tablespace files in the mysql database directory.以前,这些表是在mysql数据库目录中的单个表空间文件中创建的。

Data-at-rest encryption can be enabled for the mysql system schema tablespace. 可以为mysql系统模式表空间启用静态数据加密。For more information, see Section 15.13, “InnoDB Data-at-Rest Encryption”.有关更多信息,请参阅第15.13节,“InnoDB静止数据加密”

Data Dictionary Tables数据字典表

These tables comprise the data dictionary, which contains metadata about database objects. 这些表构成了数据字典,其中包含有关数据库对象的元数据。For additional information, see Chapter 14, MySQL Data Dictionary.有关更多信息,请参阅第14章,“MySQL数据字典”

Important重要

The data dictionary is new in MySQL 8.0. A data dictionary-enabled server entails some general operational differences compared to previous MySQL releases. 数据字典在MySQL 8.0中是新的。与以前的MySQL版本相比,启用数据字典的服务器在操作上有一些总体差异。For details, see Section 14.7, “Data Dictionary Usage Differences”. 有关详细信息,请参阅第14.7节,“数据字典用法差异”Also, for upgrades to MySQL 8.0 from MySQL 5.7, the upgrade procedure differs somewhat from previous MySQL releases and requires that you verify the upgrade readiness of your installation by checking specific prerequisites. 此外,对于从MySQL 5.7升级到MySQL 8.0,升级过程与以前的MySQL版本有所不同,需要通过检查特定的先决条件来验证安装的升级准备情况。For more information, see Section 2.11, “Upgrading MySQL”, particularly Section 2.11.5, “Preparing Your Installation for Upgrade”.有关更多信息,请参阅第2.11节,“升级MySQL”,特别是第2.11.5节,“准备升级安装”

  • catalogs: Catalog information.:目录信息。

  • character_sets: Information about available character sets.:有关可用字符集的信息。

  • check_constraints: Information about CHECK constraints defined on tables. :有关在表上定义的CHECK约束的信息。See Section 13.1.20.6, “CHECK Constraints”.请参阅第13.1.20.6节,“检查约束条件”

  • collations: Information about collations for each character set.:有关每个字符集的排序规则的信息。

  • column_statistics: Histogram statistics for column values. :列值的直方图统计信息。See Section 8.9.6, “Optimizer Statistics”.请参阅第8.9.6节,“优化器统计”

  • column_type_elements: Information about types used by columns.:有关列使用的类型的信息。

  • columns: Information about columns in tables.:有关表中列的信息。

  • dd_properties: A table that identifies data dictionary properties, such as its version. The server uses this to determine whether the data dictionary must be upgraded to a newer version.:一个表,用于标识数据字典属性,例如其版本。服务器使用它来确定是否必须将数据字典升级到更新的版本。

  • events: Information about Event Scheduler events. :有关事件计划程序事件的信息。See Section 25.4, “Using the Event Scheduler”. 请参阅第25.4节,“使用事件调度器”If the server is started with the --skip-grant-tables option, the event scheduler is disabled and events registered in the table do not run. 如果服务器是使用--skip-grant-tables选项启动的,则会禁用事件调度程序,并且表中注册的事件不会运行。See Section 25.4.2, “Event Scheduler Configuration”.请参阅第25.4.2节,“事件调度器配置”

  • foreign_keys, foreign_key_column_usage: Information about foreign keys.:有关外键的信息。

  • index_column_usage: Information about columns used by indexes.:有关索引使用的列的信息。

  • index_partitions: Information about partitions used by indexes.:有关索引使用的分区的信息。

  • index_stats: Used to store dynamic index statistics generated when ANALYZE TABLE is executed.:用于存储在执行ANALYZE TABLE时生成的动态索引统计信息。

  • indexes: Information about table indexes.:有关表索引的信息。

  • innodb_ddl_log: Stores DDL logs for crash-safe DDL operations.:存储用于崩溃安全DDL操作的DDL日志。

  • parameter_type_elements: Information about stored procedure and function parameters, and about return values for stored functions.:有关存储过程和函数参数的信息,以及有关存储函数的返回值的信息。

  • parameters: Information about stored procedures and functions. :有关存储过程和函数的信息。See Section 25.2, “Using Stored Routines”.请参阅第25.2节,“使用存储例程”

  • resource_groups: Information about resource groups. :有关资源组的信息。See Section 5.1.16, “Resource Groups”.请参阅第5.1.16节,“资源组”

  • routines: Information about stored procedures and functions. See Section 25.2, “Using Stored Routines”.:有关存储过程和函数的信息。参见第25.2节,“使用存储例程”

  • schemata: Information about schemata. In MySQL, a schema is a database, so this table provides information about databases.:关于schemata的信息。在MySQL中,模式是数据库,因此此表提供了有关数据库的信息。

  • st_spatial_reference_systems: Information about available spatial reference systems for spatial data.:关于空间数据的可用空间参考系统的信息。

  • table_partition_values: Information about values used by table partitions.:有关表分区使用的值的信息。

  • table_partitions: Information about partitions used by tables.:有关表使用的分区的信息。

  • table_stats: Information about dynamic table statistics generated when ANALYZE TABLE is executed.:有关在执行ANALYZE TABLE时生成的动态表统计信息。

  • tables: Information about tables in databases.:有关数据库中表的信息。

  • tablespace_files: Information about files used by tablespaces.:有关表空间使用的文件的信息。

  • tablespaces: Information about active tablespaces.:有关活动表空间的信息。

  • triggers: Information about triggers.:有关触发器的信息。

  • view_routine_usage: Information about dependencies between views and stored functions used by them.:有关视图与其使用的存储函数之间的依赖关系的信息。

  • view_table_usage: Used to track dependencies between views and their underlying tables.:用于跟踪视图及其基础表之间的依赖关系。

Data dictionary tables are invisible. 数据字典表是不可见的。They cannot be read with SELECT, do not appear in the output of SHOW TABLES, are not listed in the INFORMATION_SCHEMA.TABLES table, and so forth. 它们不能用SELECT读取,不出现在SHOW TABLES的输出中,不列在INFORMATION_SCHEMATABLES表中,等等。However, in most cases there are corresponding INFORMATION_SCHEMA tables that can be queried. 但是,在大多数情况下,可以查询相应的INFORMATION_SCHEMA表。Conceptually, the INFORMATION_SCHEMA provides a view through which MySQL exposes data dictionary metadata. 从概念上讲,INFORMATION_SCHEMA提供了一个视图,MySQL通过该视图公开数据字典元数据。For example, you cannot select from the mysql.schemata table directly:例如,您不能直接从mysql.schemata表中选择:

mysql> SELECT * FROM mysql.schemata;
ERROR 3554 (HY000): Access to data dictionary table 'mysql.schemata' is rejected.

Instead, select that information from the corresponding INFORMATION_SCHEMA table:相反,从相应的INFORMATION_SCHEMA表中选择该信息:

mysql> SELECT * FROM INFORMATION_SCHEMA.SCHEMATA\G
*************************** 1. row ***************************
              CATALOG_NAME: def
               SCHEMA_NAME: mysql
DEFAULT_CHARACTER_SET_NAME: utf8mb4
    DEFAULT_COLLATION_NAME: utf8mb4_0900_ai_ci
                  SQL_PATH: NULL
        DEFAULT_ENCRYPTION: NO
*************************** 2. row ***************************
              CATALOG_NAME: def
               SCHEMA_NAME: information_schema
DEFAULT_CHARACTER_SET_NAME: utf8
    DEFAULT_COLLATION_NAME: utf8_general_ci
                  SQL_PATH: NULL
        DEFAULT_ENCRYPTION: NO
...

There is no INFORMATION_SCHEMA table that corresponds exactly to mysql.indexes, but INFORMATION_SCHEMA.STATISTICS contains much of the same information.没有与mysql.indexes完全对应的INFORMATION_SCHEMA表,但INFORMATION_SCHEMA.STATISTICS包含许多相同的信息。

As of yet, there are no INFORMATION_SCHEMA tables that correspond exactly to mysql.foreign_keys, mysql.foreign_key_column_usage. 到目前为止,还没有INFORMATION_SCHEMA表与mysql.foreign_keysmysql.foreign_6key_column_usage完全对应。The standard SQL way to obtain foreign key information is by using the INFORMATION_SCHEMA REFERENTIAL_CONSTRAINTS and KEY_COLUMN_USAGE tables; these tables are now implemented as views on the foreign_keys, foreign_key_column_usage, and other data dictionary tables.获取外键信息的标准SQL方法是使用INFORMATION_SCHEMA REFERENTIAL_COCONSTRAINTSKEY_COLUMN_USAGE表;这些表现在被实现为foreign_keysforeign_key_column_usage和其他数据字典表的视图。

Some system tables from before MySQL 8.0 have been replaced by data dictionary tables and are no longer present in the mysql system schema:MySQL 8.0之前的一些系统表已被数据字典表取代,并且不再出现在mysql系统模式中:

  • The events data dictionary table supersedes the event table from before MySQL 8.0.events数据字典表将取代MySQL 8.0之前的event表。

  • The parameters and routines data dictionary tables together supersede the proc table from before MySQL 8.0.parametersroutines数据字典表一起取代了MySQL 8.0之前的proc表。

Grant System TablesGrant系统表

These system tables contain grant information about user accounts and the privileges held by them. 这些系统表包含有关用户帐户及其权限的授予信息。For additional information about the structure, contents, and purpose of the these tables, see Section 6.2.3, “Grant Tables”.有关这些表格的结构、内容和用途的更多信息,请参阅第6.2.3节,“Grant表格”

As of MySQL 8.0, the grant tables are InnoDB (transactional) tables. 从MySQL 8.0开始,grant表是InnoDB(transactional)表。Previously, these were MyISAM (nontransactional) tables. 以前,这些是MyISAM(非事务性)表。The change of grant-table storage engine underlies an accompanying change in MySQL 8.0 to the behavior of account-management statements such as CREATE USER and GRANT. grant表存储引擎的更改是MySQL 8.0中对帐户管理语句(如CREATE USERGRANT)行为的相应更改的基础。Previously, an account-management statement that named multiple users could succeed for some users and fail for others. 以前,命名多个用户的帐户管理语句对某些用户可能成功,对其他用户可能失败。The statements are now transactional and either succeed for all named users or roll back and have no effect if any error occurs.这些语句现在是事务性的,要么对所有命名用户成功,要么回滚,如果出现任何错误,则不起作用。

Note注意

If MySQL is upgraded from an older version but the grant tables have not been upgraded from MyISAM to InnoDB, the server considers them read only and account-management statements produce an error. 如果MySQL是从旧版本升级的,但授权表尚未从MyISAM升级到InnoDB,则服务器会认为它们是只读的,并且帐户管理语句会产生错误。For upgrade instructions, see Section 2.11, “Upgrading MySQL”.有关升级说明,请参阅第2.11节,“升级MySQL”

  • user: User accounts, global privileges, and other nonprivilege columns.:用户帐户、全局特权和其他非特权列。

  • global_grants: Assignments of dynamic global privileges to users; see Static Versus Dynamic Privileges.:为用户分配动态全局权限;请参阅静态权限与动态权限

  • db: Database-level privileges.:数据库级别的权限。

  • tables_priv: Table-level privileges.:表级特权。

  • columns_priv: Column-level privileges.:列级特权。

  • procs_priv: Stored procedure and function privileges.:存储过程和函数权限。

  • proxies_priv: Proxy-user privileges.:代理用户权限。

  • default_roles: This table lists default roles to be activated after a user connects and authenticates, or executes SET ROLE DEFAULT.:此表列出了用户连接并验证或执行SET ROLE DEFAULT后要激活的默认角色。

  • role_edges: This table lists edges for role subgraphs.:此表列出了角色子图的边。

    A given user table row might refer to a user account or a role. 给定的user表行可能引用用户帐户或角色。The server can distinquish whether a row represents a user account, a role, or both by consulting the role_edges table for information about relations between authentication IDs.服务器可以通过查阅role_edges表以获取有关身份验证ID之间关系的信息来区分一行是代表用户帐户还是代表角色,或者同时代表两者。

  • password_history: Information about password changes.:有关密码更改的信息。

Object Information System Tables对象信息系统表

These system tables contain information about components, loadable functions, and server-side plugins:这些系统表包含有关组件、可加载函数和服务器端插件的信息:

Log System Tables日志系统表

The server uses these system tables for logging:服务器使用以下系统表进行日志记录:

  • general_log: The general query log table.:常规查询日志表。

  • slow_log: The slow query log table.:慢速查询日志表。

Log tables use the CSV storage engine.日志表使用CSV存储引擎。

For more information, see Section 5.4, “MySQL Server Logs”.有关更多信息,请参阅第5.4节,“MySQL服务器日志”

Server-Side Help System Tables服务器端帮助系统表

These system tables contain server-side help information:这些系统表包含服务器端帮助信息:

  • help_category: Information about help categories.:有关帮助类别的信息。

  • help_keyword: Keywords associated with help topics.:与帮助主题关联的关键字。

  • help_relation: Mappings between help keywords and topics.:帮助关键字和主题之间的映射。

  • help_topic: Help topic contents.:帮助主题内容。

For more information, see Section 5.1.17, “Server-Side Help Support”.有关更多信息,请参阅第5.1.17节,“服务器端帮助支持”

Time Zone System Tables时区系统表

These system tables contain time zone information:这些系统表包含时区信息:

  • time_zone: Time zone IDs and whether they use leap seconds.:时区ID以及它们是否使用闰秒。

  • time_zone_leap_second: When leap seconds occur.:当闰秒出现时。

  • time_zone_name: Mappings between time zone IDs and names.:时区ID和名称之间的映射。

  • time_zone_transition, time_zone_transition_type: Time zone descriptions.:时区描述。

For more information, see Section 5.1.15, “MySQL Server Time Zone Support”.有关更多信息,请参阅第5.1.15节,“MySQL Server时区支持”

Replication System Tables复制系统表

The server uses these system tables to support replication:服务器使用这些系统表来支持复制:

All of the tables just listed use the InnoDB storage engine.刚才列出的所有表都使用InnoDB存储引擎。

Optimizer System TablesOptimizer系统表

These system tables are for use by the optimizer:这些系统表供优化器使用:

Miscellaneous System Tables其他系统表

Other system tables do not fit the preceding categories:其他系统表不符合上述类别:

  • audit_log_filter, audit_log_user: If MySQL Enterprise Audit is installed, these tables provide persistent storage of audit log filter definitions and user accounts. See Audit Log Tables.:如果安装了MySQL Enterprise Audit,这些表将提供审核日志筛选器定义和用户帐户的持久存储。请参阅审核日志表

  • firewall_group_allowlist, firewall_groups, firewall_memebership, firewall_users, firewall_whitelist: If MySQL Enterprise Firewall is installed, these tables provide persistent storage for information used by the firewall. See Section 6.4.7, “MySQL Enterprise Firewall”.:如果安装了MySQL企业防火墙,这些表将为防火墙使用的信息提供持久存储。请参阅第6.4.7节,“MySQL企业防火墙”

  • servers: Used by the FEDERATED storage engine. See Section 16.8.2.2, “Creating a FEDERATED Table Using CREATE SERVER”.:由FEDERATED存储引擎使用。参见第16.8.2.2节,“使用CREATE SERVER创建一个FEDERATED表”

  • innodb_dynamic_metadata: Used by the InnoDB storage engine to store fast-changing table metadata such as auto-increment counter values and index tree corruption flags. :由InnoDB存储引擎用于存储快速变化的表元数据,如自动递增计数器值和索引树损坏标志。Replaces the data dictionary buffer table that resided in the InnoDB system tablespace.替换InnoDB系统表空间中的数据字典缓冲区表。