8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

7.3 mysql 系统模式7.3 The mysql System Schema

mysql 模式是系统模式。它包含在 MySQL 服务器运行时所需存储信息的表。广义分类是 mysql 模式包含存储数据库对象元数据的数据字典表,以及用于其他操作用途的系统表。以下讨论进一步将系统表集细分为更小的类别。The mysql schema is the system schema. It contains tables that store information required by the MySQL server as it runs. 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. The following discussion further subdivides the set of system tables into smaller categories.

本节的其余部分列出了各类别的表,并提供了交叉引用以获取更多信息。除非另有说明,数据字典表和系统表使用 InnoDB 存储引擎。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.

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

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

数据字典表Data Dictionary Tables

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

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

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

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

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

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

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

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

  • dd_properties:一个标识数据字典属性的表,例如其版本。服务器使用此信息来确定是否必须将数据字典升级到较新版本。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:有关事件调度器事件的信息。参见 第 27.4 节,“使用事件调度器”。如果服务器使用 --skip-grant-tables 选项启动,则事件调度器被禁用,并且表中注册的事件不会运行。参见 第 27.4.2 节,“事件调度器配置”。events: Information about Event Scheduler events. See Section 27.4, “Using the Event Scheduler”. 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. See Section 27.4.2, “Event Scheduler Configuration”.

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

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

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

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

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

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

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

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

  • resource_groups:资源组的信息。参见 第 7.1.16 节,“资源组”。resource_groups: Information about resource groups. See Section 7.1.16, “Resource Groups”.

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

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

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

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

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

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

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

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

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

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

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

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

数据字典表是不可见的。它们不能通过 SELECT 读取,不会出现在 SHOW TABLES 的输出中,也不会列在 INFORMATION_SCHEMA.TABLES 表中,等等。然而,在大多数情况下,有相应的 INFORMATION_SCHEMA 表可以查询。从概念上来说,INFORMATION_SCHEMA 提供了一个视图,通过它 MySQL 暴露数据字典元数据。例如,您不能直接从 mysql.schemata 表中进行选择: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. However, in most cases there are corresponding INFORMATION_SCHEMA tables that can be queried. Conceptually, the INFORMATION_SCHEMA provides a view through which MySQL exposes data dictionary metadata. For example, you cannot select from the mysql.schemata table directly:

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

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

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: utf8mb3
    DEFAULT_COLLATION_NAME: utf8mb3_general_ci
                  SQL_PATH: NULL
        DEFAULT_ENCRYPTION: NO
*************************** 3. row ***************************
              CATALOG_NAME: def
               SCHEMA_NAME: performance_schema
DEFAULT_CHARACTER_SET_NAME: utf8mb4
    DEFAULT_COLLATION_NAME: utf8mb4_0900_ai_ci
                  SQL_PATH: NULL
        DEFAULT_ENCRYPTION: NO
...

没有与 mysql.indexes 完全对应的信息模式表,但 INFORMATION_SCHEMA.STATISTICS 包含了大部分相同的信息。There is no Information Schema table that corresponds exactly to mysql.indexes, but INFORMATION_SCHEMA.STATISTICS contains much of the same information.

到目前为止,还没有与 mysql.foreign_keys、mysql.foreign_key_column_usage 完全对应的 INFORMATION_SCHEMA 表。获取外键信息的标准 SQL 方法是使用 INFORMATION_SCHEMA 的 REFERENTIAL_CONSTRAINTS 和 KEY_COLUMN_USAGE 表;这些表现在被实现为基于 foreign_keys、foreign_key_column_usage 及其他数据字典表的视图。As of yet, there are no INFORMATION_SCHEMA tables that correspond exactly to mysql.foreign_keys, mysql.foreign_key_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.

授权系统表Grant System Tables

这些系统表包含有关用户账户及其拥有的权限的信息。有关这些表的结构、内容和用途的更多信息,请参见 第 8.2.3 节,“授权表”。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 8.2.3, “Grant Tables”.

MySQL 8.4 的授权表是 InnoDB(事务型)表。账户管理语句是事务性的,并且对于所有指定用户要么全部成功,要么在发生任何错误时回滚且无任何效果。The MySQL 8.4 grant tables are InnoDB (transactional) tables. Account-management statements are transactional and either succeed for all named users or roll back and have no effect if any error occurs.

  • user:用户账户、全局权限以及其他非权限列。user: User accounts, global privileges, and other nonprivilege columns.

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

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

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

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

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

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

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

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

    给定的 user 表行可能指的是一个用户账户或一个角色。服务器可以通过查询 role_edges 表中关于身份验证 ID 之间关系的信息来区分某行代表用户账户、角色,或两者兼有。A given user table row might refer to a user account or a role. The server can distinguish whether a row represents a user account, a role, or both by consulting the role_edges table for information about relations between authentication IDs.

  • password_history:关于密码更改的信息。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:通用查询日志表。 general_log: The general query log table.

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

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

更多信息,请参见 第 7.4 节,“MySQL 服务器日志”。For more information, see Section 7.4, “MySQL Server Logs”.

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

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

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

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

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

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

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

时区系统表Time Zone System Tables

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

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

  • time_zone_leap_second:闰秒发生的时间。 time_zone_leap_second: When leap seconds occur.

  • time_zone_name:时区 ID 与名称的映射关系。 time_zone_name: Mappings between time zone IDs and names.

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

有关更多信息,请参见 第 7.1.15 节,“MySQL 服务器时区支持”。For more information, see Section 7.1.15, “MySQL Server Time Zone Support”.

复制系统表Replication System Tables

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

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

优化器系统表Optimizer System Tables

这些系统表供优化器使用: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:如果安装了 MySQL 企业审计,这些表提供审计日志过滤器定义和用户账户的持久存储。参见 审计日志表。 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.

  • firewall_group_allowlist、firewall_groups、firewall_memebership、firewall_users、firewall_whitelist:如果安装了 MySQL 企业防火墙,这些表提供用于防火墙信息的持久存储。请参阅 第 8.4.7 节,“MySQL 企业防火墙”。 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 8.4.7, “MySQL Enterprise Firewall”.

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

  • innodb_dynamic_metadata:由 InnoDB 存储引擎用于存储快速变化的表元数据,例如自增计数器值和索引树损坏标志。它取代了原本位于 InnoDB 系统表空间中的数据字典缓冲表。 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. Replaces the data dictionary buffer table that resided in the InnoDB system tablespace.