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”.
这些表组成了数据字典,其中包含有关数据库对象的元数据。欲了解更多信息,请参见 第 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 aboutCHECKconstraints 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-tablesoption, 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 whenANALYZE TABLEis 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 whenANALYZE TABLEis 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.
这些系统表包含有关用户账户及其拥有的权限的信息。有关这些表的结构、内容和用途的更多信息,请参见 第 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 executesSET ROLE DEFAULT.role_edges:此表列出角色子图的边。role_edges: This table lists edges for role subgraphs.给定的
user表行可能指的是一个用户账户或一个角色。服务器可以通过查询role_edges表中关于身份验证 ID 之间关系的信息来区分某行代表用户账户、角色,或两者兼有。A givenusertable 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 therole_edgestable for information about relations between authentication IDs.password_history:关于密码更改的信息。password_history: Information about password changes.
这些系统表包含有关组件、可加载函数和服务器端插件的信息:These system tables contain information about components, loadable functions, and server-side plugins:
component:使用INSTALL COMPONENT安装的服务器组件的注册表。此表中列出的任何组件都会在服务器启动序列期间由加载服务安装。参见 第 7.5.1 节,“安装和卸载组件”。component: The registry for server components installed usingINSTALL COMPONENT. Any components listed in this table are installed by a loader service during the server startup sequence. See Section 7.5.1, “Installing and Uninstalling Components”.func:用于可加载函数的注册表,这些函数是通过CREATE FUNCTION安装的。在正常启动过程中,服务器会加载在此表中注册的函数。如果服务器使用--skip-grant-tables选项启动,则表中注册的函数不会被加载,也无法使用。参见 第 7.7.1 节,“安装和卸载可加载函数”。func: The registry for loadable functions installed usingCREATE FUNCTION. During the normal startup sequence, the server loads functions registered in this table. If the server is started with the--skip-grant-tablesoption, functions registered in the table are not loaded and are unavailable. See Section 7.7.1, “Installing and Uninstalling Loadable Functions”.Note像
mysql.func系统表一样,性能模式user_defined_functions表列出了使用CREATE FUNCTION安装的可加载函数。与mysql.func表不同,user_defined_functions表还列出了由服务器组件或插件自动安装的函数。这个差异使得user_defined_functions在检查已安装函数时比mysql.func更加可取。参见 第 29.12.22.10 节,“user_defined_functions 表”。Like themysql.funcsystem table, the Performance Schemauser_defined_functionstable lists loadable functions installed usingCREATE FUNCTION. Unlike themysql.functable, theuser_defined_functionstable also lists functions installed automatically by server components or plugins. This difference makesuser_defined_functionspreferable tomysql.funcfor checking which functions are installed. See Section 29.12.22.10, “The user_defined_functions Table”.plugin:用于服务器端插件的注册表,这些插件是通过INSTALL PLUGIN安装的。在正常启动过程中,服务器会加载在此表中注册的插件。如果服务器使用--skip-grant-tables选项启动,则表中注册的插件不会被加载,也不可用。请参阅 第 7.6.1 节,“安装和卸载插件”。plugin: The registry for server-side plugins installed usingINSTALL PLUGIN. During the normal startup sequence, the server loads plugins registered in this table. If the server is started with the--skip-grant-tablesoption, plugins registered in the table are not loaded and are unavailable. See Section 7.6.1, “Installing and Uninstalling Plugins”.
服务器使用这些系统表进行日志记录:The server uses these system tables for logging:
日志表使用 CSV 存储引擎。Log tables use the CSV storage engine.
更多信息,请参见 第 7.4 节,“MySQL 服务器日志”。For more information, see Section 7.4, “MySQL Server Logs”.
这些系统表包含服务器端的帮助信息:These system tables contain server-side help information:
更多信息,请参见 第 7.1.17 节,“服务器端帮助支持”。For more information, see Section 7.1.17, “Server-Side Help Support”.
这些系统表包含时区信息: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”.
服务器使用这些系统表来支持复制:The server uses these system tables to support replication:
gtid_executed:用于存储 GTID 值的表。请参阅 mysql.gtid_executed 表。gtid_executed: Table for storing GTID values. See mysql.gtid_executed Table.ndb_binlog_index:NDB 集群复制的二进制日志信息。只有在服务器使用NDBCLUSTER支持构建时才会创建此表。参见 第 25.7.4 节,“NDB Cluster 复制模式和表”。ndb_binlog_index: Binary log information for NDB Cluster replication. This table is created only if the server is built withNDBCLUSTERsupport. See Section 25.7.4, “NDB Cluster Replication Schema and Tables”.slave_master_info、slave_relay_log_info、slave_worker_info:用于在从服务器上存储复制信息。参见 第 19.2.4 节,“中继日志和复制元数据存储库”。slave_master_info,slave_relay_log_info,slave_worker_info: Used to store replication information on replica servers. See Section 19.2.4, “Relay Log and Replication Metadata Repositories”.
刚才列出的所有表都使用 InnoDB 存储引擎。All of the tables just listed use the
InnoDB storage engine.
这些系统表供优化器使用:These system tables are for use by the optimizer:
innodb_index_stats,innodb_table_stats:用于InnoDB持久化优化器统计信息。参见 第 17.8.10.1 节,“配置持久化优化器统计参数”。innodb_index_stats,innodb_table_stats: Used forInnoDBpersistent optimizer statistics. See Section 17.8.10.1, “Configuring Persistent Optimizer Statistics Parameters”.server_cost,engine_cost:优化器成本模型使用包含关于查询执行期间发生的操作成本估算信息的表。server_cost包含通用服务器操作的优化器成本估算。engine_cost包含特定存储引擎操作的估算。参见 第 10.9.5 节,“优化器成本模型”。server_cost,engine_cost: The optimizer cost model uses tables that contain cost estimate information about operations that occur during query execution.server_costcontains optimizer cost estimates for general server operations.engine_costcontains estimates for operations specific to particular storage engines. See Section 10.9.5, “The Optimizer Cost Model”.
其他系统表不属于前述类别: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 theFEDERATEDstorage engine. See Section 18.8.2.2, “Creating a FEDERATED Table Using CREATE SERVER”.innodb_dynamic_metadata:由InnoDB存储引擎用于存储快速变化的表元数据,例如自增计数器值和索引树损坏标志。它取代了原本位于InnoDB系统表空间中的数据字典缓冲表。innodb_dynamic_metadata: Used by theInnoDBstorage 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 theInnoDBsystem tablespace.