使用启用了数据字典的 MySQL 服务器,与未启用数据字典的服务器相比,在操作上会有一些差异:Use of a data dictionary-enabled MySQL server entails some operational differences compared to a server that does not have a data dictionary:
以前,启用
innodb_read_only系统变量只会阻止为InnoDB存储引擎创建和删除表。从 MySQL 8.4 开始,启用innodb_read_only会阻止对所有存储引擎执行这些操作。任何存储引擎的表创建和删除操作都会修改mysql系统数据库中的数据字典表,但这些表使用InnoDB存储引擎,在启用innodb_read_only时无法修改。其他需要修改数据字典表的表操作也遵循相同的原则。示例:Previously, enabling theinnodb_read_onlysystem variable prevented creating and dropping tables only for theInnoDBstorage engine. As of MySQL 8.4, enablinginnodb_read_onlyprevents these operations for all storage engines. Table creation and drop operations for any storage engine modify data dictionary tables in themysqlsystem database, but those tables use theInnoDBstorage engine and cannot be modified wheninnodb_read_onlyis enabled. The same principle applies to other table operations that require modifying data dictionary tables. Examples:ANALYZE TABLE失败,因为它会更新存储在数据字典中的表统计信息。ANALYZE TABLEfails because it updates table statistics, which are stored in the data dictionary.ALTER TABLE tbl_name ENGINE=engine_name失败,因为它会更新存储在数据字典中的存储引擎指定信息。ALTER TABLEfails because it updates the storage engine designation, which is stored in the data dictionary.tbl_nameENGINE=engine_name
Note启用
innodb_read_only对mysql系统数据库中的非数据字典表也有重要影响。详情请参阅innodb_read_only在 第 17.14 节,“InnoDB 启动选项和系统变量” 中的描述。Enablinginnodb_read_onlyalso has important implications for non-data dictionary tables in themysqlsystem database. For details, see the description ofinnodb_read_onlyin Section 17.14, “InnoDB Startup Options and System Variables”以前,
mysql系统数据库中的表对 DML 和 DDL 语句是可见的。从 MySQL 8.4 起,数据字典表不可见,不能直接修改或查询。然而,在大多数情况下,可以查询相应的INFORMATION_SCHEMA表来替代。这使得在服务器开发过程中,可以修改底层数据字典表,同时为应用使用保持稳定的INFORMATION_SCHEMA接口。Previously, tables in themysqlsystem database were visible to DML and DDL statements. As of MySQL 8.4, data dictionary tables are invisible and cannot be modified or queried directly. However, in most cases there are correspondingINFORMATION_SCHEMAtables that can be queried instead. This enables the underlying data dictionary tables to be changed as server development proceeds, while maintaining a stableINFORMATION_SCHEMAinterface for application use.MySQL 8.4 中的
INFORMATION_SCHEMA表与数据字典紧密关联,导致一些使用上的差异:INFORMATION_SCHEMAtables in MySQL 8.4 are closely tied to the data dictionary, resulting in several usage differences:以前,
INFORMATION_SCHEMA对STATISTICS和TABLES表中表统计信息的查询,是直接从存储引擎中获取统计信息的。从 MySQL 8.4 起,默认使用缓存的表统计信息。information_schema_stats_expiry系统变量定义了缓存表统计信息过期前的时间周期。默认值是 86400 秒(24 小时)。(要随时更新指定表的缓存值,请使用ANALYZE TABLE。) 如果没有缓存的统计信息或统计信息已过期,在查询表统计信息列时,统计信息会从存储引擎中获取。要始终直接从存储引擎获取最新统计信息,请将information_schema_stats_expiry设置为0。更多信息,请参见 第 10.2.3 节,“优化 INFORMATION_SCHEMA 查询”。Previously,INFORMATION_SCHEMAqueries for table statistics in theSTATISTICSandTABLEStables retrieved statistics directly from storage engines. As of MySQL 8.4, cached table statistics are used by default. Theinformation_schema_stats_expirysystem variable defines the period of time before cached table statistics expire. The default is 86400 seconds (24 hours). (To update the cached values at any time for a given table, useANALYZE TABLE.) If there are no cached statistics or statistics have expired, statistics are retrieved from storage engines when querying table statistics columns. To always retrieve the latest statistics directly from storage engines, setinformation_schema_stats_expiryto0. For more information, see Section 10.2.3, “Optimizing INFORMATION_SCHEMA Queries”.一些
INFORMATION_SCHEMA表是数据字典表的视图,这使得优化器能够使用这些基础表上的索引。因此,根据优化器的选择,INFORMATION_SCHEMA查询结果的行顺序可能与以前的结果不同。如果查询结果必须具有特定的行排序特性,请包含ORDER BY子句。SeveralINFORMATION_SCHEMAtables are views on data dictionary tables, which enables the optimizer to use indexes on those underlying tables. Consequently, depending on optimizer choices, the row order of results forINFORMATION_SCHEMAqueries might differ from previous results. If a query result must have specific row ordering characteristics, include anORDER BYclause.对
INFORMATION_SCHEMA表的查询可能返回的列名与早期 MySQL 系列中的字母大小写不同。应用程序应以不区分大小写的方式测试结果集列名。如果这不可行,一种解决方法是在选择列表中使用列别名以返回所需字母大小写的列名。例如:Queries onINFORMATION_SCHEMAtables may return column names in a different lettercase than in earlier MySQL series. Applications should test result set column names in case-insensitive fashion. If that is not feasible, a workaround is to use column aliases in the select list that return column names in the required lettercase. For example:SELECT TABLE_SCHEMA AS table_schema, TABLE_NAME AS table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'users';
mysqldump 再也不会导出
INFORMATION_SCHEMA数据库,即使在命令行中显式指定。mysqldump no longer dumps theINFORMATION_SCHEMAdatabase, even if explicitly named on the command line.CREATE TABLE dst_tbl LIKE src_tbl要求src_tbl是基表,如果它是INFORMATION_SCHEMA表(即基于数据字典表的视图),则会失败。CREATE TABLErequires thatdst_tblLIKEsrc_tblsrc_tblbe a base table and fails if it is anINFORMATION_SCHEMAtable that is a view on data dictionary tables.以前,从
INFORMATION_SCHEMA表中选择的列的结果集标题会按照查询中指定的大小写显示。此查询生成的结果集标题为table_name:Previously, result set headers of columns selected fromINFORMATION_SCHEMAtables used the capitalization specified in the query. This query produces a result set with a header oftable_name:SELECT table_name FROM INFORMATION_SCHEMA.TABLES;
从 MySQL 8.4 开始,这些标题会使用大写;之前的查询生成的结果集标题为
TABLE_NAME。如有必要,可以使用列别名来实现不同的字母大小写。例如:As of MySQL 8.4, these headers are capitalized; the preceding query produces a result set with a header ofTABLE_NAME. If necessary, a column alias can be used to achieve a different lettercase. For example:SELECT table_name AS 'table_name' FROM INFORMATION_SCHEMA.TABLES;
数据目录会影响 mysqldump 如何导出
mysql系统数据库的信息:The data directory affects how mysqldump dumps information from themysqlsystem database:mysqldump 仅导出该数据库中的非数据字典表,而之前可以导出
mysql系统数据库中的所有表。mysqldump only dumps non-data dictionary tables in that database, when previously it was possible to dump all tables in themysqlsystem database.以前,在使用
--all-databases选项时,不需要使用--routines和--events选项来包含存储过程和事件:因为导出会包括mysql系统数据库,因此也会包括包含存储过程和事件定义的proc和event表。从 MySQL 8.4 开始,不再使用event和proc表。对应对象的定义存储在数据字典表中,但这些表不会被导出。要在使用--all-databases所做的导出中包含存储过程和事件,需要显式使用--routines和--events选项。Previously, the--routinesand--eventsoptions were not required to include stored routines and events when using the--all-databasesoption: The dump included themysqlsystem database, and therefore also theprocandeventtables containing stored routine and event definitions. As of MySQL 8.4, theeventandproctables are not used. Definitions for the corresponding objects are stored in data dictionary tables, but those tables are not dumped. To include stored routines and events in a dump made using--all-databases, use the--routinesand--eventsoptions explicitly.之前,
--routines选项需要对proc表具有SELECT权限。从 MySQL 8.4 开始,该表不再使用;--routines现在需要全局SELECT权限。Previously, the--routinesoption required theSELECTprivilege for theproctable. As of MySQL 8.4, that table is not used;--routinesrequires the globalSELECTprivilege instead.之前,可以通过转储
proc和event表来同时转储存储例程和事件定义及其创建和修改时间戳。从 MySQL 8.4 开始,这些表不再使用,因此无法转储时间戳。Previously, it was possible to dump stored routine and event definitions together with their creation and modification timestamps, by dumping theprocandeventtables. As of MySQL 8.4, those tables are not used, so it is not possible to dump timestamps.
之前,创建包含非法字符的存储例程会产生警告。从 MySQL 8.4 开始,这将成为错误。Previously, creating a stored routine that contains illegal characters produced a warning. As of MySQL 8.4, this is an error.