MySQL 8.4 包含一个 ddl_rewriter 插件,它在服务器解析和执行收到的 CREATE TABLE 语句之前对其进行修改。该插件会移除 ENCRYPTION、DATA DIRECTORY 和 INDEX
DIRECTORY 子句,这在从加密的数据库或将表存储在数据目录外的数据库创建的 SQL 转储文件中恢复表时可能会很有用。例如,该插件可以使将此类转储文件恢复到未加密实例或无法访问数据目录外路径的环境中成为可能。MySQL 8.4 includes a ddl_rewriter
plugin that modifies CREATE TABLE
statements received by the server before it parses and executes
them. The plugin removes ENCRYPTION,
DATA DIRECTORY, and INDEX
DIRECTORY clauses, which may be helpful when restoring
tables from SQL dump files created from databases that are
encrypted or that have their tables stored outside the data
directory. For example, the plugin may enable restoring such dump
files into an unencrypted instance or in an environment where the
paths outside the data directory are not accessible.
在使用 ddl_rewriter 插件之前,请按照 第 7.6.5.1 节,“安装或卸载 ddl_rewriter” 中提供的说明进行安装。Before using the ddl_rewriter plugin, install
it according to the instructions provided in
Section 7.6.5.1, “Installing or Uninstalling ddl_rewriter”.
ddl_rewriter 会在服务器解析之前检查收到的 SQL 语句,并根据以下条件重写它们:ddl_rewriter examines SQL statements received
by the server prior to parsing, rewriting them according to these
conditions:
ddl_rewriter只考虑CREATE TABLE句,且仅当这些语句是独立的语句,出现在输入行开头或预备语句文本开头时。ddl_rewriter不考虑CREATE TABLE句。语句可以跨多行扩展。ddl_rewriterconsiders onlyCREATE TABLEstatements, and only if they are standalone statements that occur at the beginning of an input line or at the beginning of prepared statement text.ddl_rewriterdoes not considerCREATE TABLEstatements within stored program definitions. Statements can extend over multiple lines.在考虑重写的语句中,以下子句的实例将被重写,并且每个实例都将被替换为一个空格:Within statements considered for rewrite, instances of the following clauses are rewritten and each instance replaced by a single space:
ENCRYPTIONENCRYPTIONDATA DIRECTORY(在表和分区级别)DATA DIRECTORY(at the table and partition levels)INDEX DIRECTORY(在表和分区级别)INDEX DIRECTORY(at the table and partition levels)
重写不依赖于字母大小写。Rewriting does not depend on lettercase.
如果 ddl_rewriter 重写了一个语句,它会生成一个警告:If ddl_rewriter rewrites a statement, it
generates a warning:
mysql>CREATE TABLE t (i INT) DATA DIRECTORY '/var/mysql/data';Query OK, 0 rows affected, 1 warning (0.03 sec) mysql>SHOW WARNINGS\G*************************** 1. row *************************** Level: Note Code: 1105 Message: Query 'CREATE TABLE t (i INT) DATA DIRECTORY '/var/mysql/data'' rewritten to 'CREATE TABLE t (i INT) ' by a query rewrite plugin 1 row in set (0.00 sec)
如果启用了通用查询日志或二进制日志,服务器会将经 ddl_rewriter 重写后的语句写入其中。If the general query log or binary log is enabled, the server
writes to it statements as they appear after any rewriting by
ddl_rewriter.
安装后,ddl_rewriter 会公开 Performance Schema 的 memory/rewriter/ddl_rewriter 工具,用于跟踪插件内存使用情况。请参见 第 29.12.20.10 节,“内存汇总表”When installed, ddl_rewriter exposes the
Performance Schema memory/rewriter/ddl_rewriter
instrument for tracking plugin memory use. See
Section 29.12.20.10, “Memory Summary Tables”