FLUSH [NO_WRITE_TO_BINLOG | LOCAL] {
flush_option [, flush_option] ...
| tables_option
}
flush_option: {
BINARY LOGS
| ENGINE LOGS
| ERROR LOGS
| GENERAL LOGS
| HOSTS
| LOGS
| PRIVILEGES
| OPTIMIZER_COSTS
| RELAY LOGS [FOR CHANNEL channel]
| SLOW LOGS
| STATUS
| USER_RESOURCES
}
tables_option: {
TABLES
| TABLES tbl_name [, tbl_name] ...
| TABLES WITH READ LOCK
| TABLES tbl_name [, tbl_name] ... WITH READ LOCK
| TABLES tbl_name [, tbl_name] ... FOR EXPORT
}
The FLUSH statement has several variant forms that clear or reload various internal caches, flush tables, or acquire locks. FLUSH语句有几种不同的形式,可以清除或重新加载各种内部缓存、缓冲表或获取锁。Each 每个FLUSH operation requires the privileges indicated in its description.FLUSH操作都需要其说明中指定的权限。
It is not possible to issue 无法在存储的函数或触发器中发出FLUSH statements within stored functions or triggers. FLUSH语句。However, you may use 但是,只要存储过程不是从存储函数或触发器调用的,就可以在存储过程中使用FLUSH in stored procedures, so long as these are not called from stored functions or triggers. FLUSH。See Section 25.8, “Restrictions on Stored Programs”.请参阅第25.8节,“存储程序的限制”。
By default, the server writes 默认情况下,服务器将FLUSH statements to the binary log so that they replicate to replicas. FLUSH语句写入二进制日志,以便它们复制到副本。To suppress logging, specify the optional 要禁止记录,请指定可选的NO_WRITE_TO_BINLOG keyword or its alias LOCAL.NO_WRITE_To_BINLOG关键字或其别名LOCAL。
FLUSH LOGS, FLUSH BINARY LOGS, FLUSH TABLES WITH READ LOCK (with or without a table list), and FLUSH TABLES are not written to the binary log in any case because they would cause problems if replicated to a replica.tbl_name ... FOR EXPORT
The FLUSH statement causes an implicit commit. FLUSH语句导致隐式提交。See Section 13.3.3, “Statements That Cause an Implicit Commit”.请参阅第13.3.3节,“导致隐式提交的语句”。
The mysqladmin utility provides a command-line interface to some flush operations, using commands such as flush-hosts, flush-logs, flush-privileges, flush-status, and flush-tables. See Section 4.5.2, “mysqladmin — A MySQL Server Administration Program”.
Sending a SIGHUP or SIGUSR1 signal to the server causes several flush operations to occur that are similar to various forms of the FLUSH statement. Signals can be sent by the 信号可以由root system account or the system account that owns the server process. root系统帐户或拥有服务器进程的系统帐户发送。This enables the flush operations to be performed without having to connect to the server, which requires a MySQL account that has privileges sufficient for those operations. 这使得刷新操作可以在不必连接到服务器的情况下执行,而服务器需要一个拥有足够权限进行这些操作的MySQL帐户。See Section 4.10, “Unix Signal Handling in MySQL”.请参阅第4.10节,“MySQL中的Unix信号处理”。
The RESET statement is similar to FLUSH. RESET语句类似于FLUSH。See Section 13.7.8.6, “RESET Statement”, for information about using 请参阅第13.7.8.6节,“RESET语句”,以了解有关在复制中使用RESET with replication.RESET的信息。
The following list describes the permitted FLUSH statement flush_option values. For descriptions of the permitted tables_option values, see FLUSH TABLES Syntax.
Closes and reopens any binary log file to which the server is writing. 关闭并重新打开服务器正在写入的任何二进制日志文件。If binary logging is enabled, the sequence number of the binary log file is incremented by one relative to the previous file.如果启用了二进制日志记录,二进制日志文件的序列号将相对于上一个文件增加一。
This operation requires the 此操作需要RELOAD privilege.RELOAD权限。
Closes and reopens any flushable logs for installed storage engines. 关闭并重新打开已安装存储引擎的所有可清洗日志。This causes 这会导致InnoDB to flush its logs to disk.InnoDB将其日志刷新到磁盘。
This operation requires the 此操作需要RELOAD privilege.RELOAD权限。
Closes and reopens any error log file to which the server is writing.关闭并重新打开服务器正在写入的任何错误日志文件。
This operation requires the 此操作需要RELOAD privilege.RELOAD权限。
Closes and reopens any general query log file to which the server is writing.关闭并重新打开服务器正在写入的任何常规查询日志文件。
This operation requires the 此操作需要RELOAD privilege.RELOAD权限。
This operation has no effect on tables used for the general query log (see Section 5.4.1, “Selecting General Query Log and Slow Query Log Output Destinations”).此操作对用于常规查询日志的表没有影响(请参阅第5.4.1节,“选择常规查询日志和慢速查询日志输出目标”)。
Empties the host cache and the Performance Schema 清空主机缓存和公开缓存内容的性能架构host_cache table that exposes the cache contents, and unblocks any blocked hosts.host_cache表,并取消阻止任何被阻止的主机。
This operation requires the 此操作需要RELOAD privilege.RELOAD权限。
For information about why host cache flushing might be advisable or desirable, see Section 5.1.12.3, “DNS Lookups and the Host Cache”.有关为什么建议或希望刷新主机缓存的信息,请参阅第5.1.12.3节,“DNS查找和主机缓存”。
从MySQL 8.0.23开始,FLUSH HOSTS is deprecated as of MySQL 8.0.23; expect it to be removed in a future MySQL release. FLUSH HOSTS已被弃用;预计它将在未来的MySQL版本中被删除。Instead, truncate the Performance Schema 而是截断性能模式host_cache table:host_cache表:
TRUNCATE TABLE performance_schema.host_cache;
The TRUNCATE TABLE operation requires the DROP privilege for the table rather than the RELOAD privilege.
Closes and reopens any log file to which the server is writing.
This operation requires the 此操作需要RELOAD privilege.RELOAD权限。
The effect of this operation is equivalent to the combined effects of these operations:该操作的效果相当于这些操作的综合效果:
FLUSH BINARY LOGS FLUSH ENGINE LOGS FLUSH ERROR LOGS FLUSH GENERAL LOGS FLUSH RELAY LOGS FLUSH SLOW LOGS
Re-reads the cost model tables so that the optimizer starts using the current cost estimates stored in them.重新读取成本模型表,以便优化器开始使用其中存储的当前成本估算。
This operation requires the 此操作需要FLUSH_OPTIMIZER_COSTS or RELOAD privilege.FLUSH_OPTIMIZER_COSTS或RELOAD权限。
The server writes a warning to the error log for any unrecognized cost model table entries. 对于任何无法识别的成本模型表条目,服务器会将警告写入错误日志。For information about these tables, see Section 8.9.5, “The Optimizer Cost Model”. 有关这些表格的信息,请参阅第8.9.5节,“优化器成本模型”。This operation affects only sessions that begin subsequent to the flush. 此操作仅影响刷新之后开始的会话。Existing sessions continue to use the cost estimates that were current when they began.现有课程继续使用课程开始时的成本估算。
Re-reads the privileges from the grant tables in the 从mysql system schema. mysql系统模式中的授权表中重新读取权限。As part of this operation, the server reads the 作为此操作的一部分,服务器读取包含动态权限分配的global_grants table containing dynamic privilege assignments and registers any unregistered privileges found there.global_grants表,并注册在其中找到的任何未注册权限。
This operation requires the 此操作需要RELOAD privilege.RELOAD权限。
If the --skip-grant-tables option was specified at server startup to disable the MySQL privilege system, FLUSH PRIVILEGES provides a way to enable the privilege system at runtime.
Resets failed-login tracking (or enables it if the server was started with 重置失败的登录跟踪(如果服务器是用--skip-grant-tables) and unlocks any temporarily locked accounts. --skip-grant-tables启动的,则启用它),并解锁所有临时锁定的帐户。See Section 6.2.15, “Password Management”.请参阅第6.2.15节,“密码管理”。
Frees memory cached by the server as a result of GRANT, CREATE USER, CREATE SERVER, and INSTALL PLUGIN statements. This memory is not released by the corresponding REVOKE, DROP USER, DROP SERVER, and UNINSTALL PLUGIN statements, so for a server that executes many instances of the statements that cause caching, there is an increase in cached memory use unless it is freed with FLUSH PRIVILEGES.
Clears the in-memory cache used by the 清除caching_sha2_password authentication plugin. caching_sha2_password验证插件使用的内存缓存。See Cache Operation for SHA-2 Pluggable Authentication.请参阅有关SHA-2可插拔身份验证的缓存操作。
FLUSH RELAY LOGS [FOR CHANNEL channel]
Closes and reopens any relay log file to which the server is writing. 关闭并重新打开服务器正在写入的所有中继日志文件。If relay logging is enabled, the sequence number of the relay log file is incremented by one relative to the previous file.如果启用了中继日志记录,则中继日志文件的序列号将相对于上一个文件增加一。
This operation requires the 此操作需要RELOAD privilege.RELOAD权限。
The FOR CHANNEL clause enables you to name which replication channel the operation applies to. Execute channelFLUSH RELAY LOGS FOR CHANNEL to flush the relay log for a specific replication channel. If no channel is named and no extra replication channels exist, the operation applies to the default channel. If no channel is named and multiple replication channels exist, the operation applies to all replication channels. For more information, see Section 17.2.2, “Replication Channels”.channel
Closes and reopens any slow query log file to which the server is writing.关闭并重新打开服务器正在写入的任何慢速查询日志文件。
This operation requires the 此操作需要RELOAD privilege.RELOAD权限。
This operation has no effect on tables used for the slow query log (see Section 5.4.1, “Selecting General Query Log and Slow Query Log Output Destinations”).此操作对用于慢速查询日志的表没有影响(请参阅第5.4.1节,“选择常规查询日志和慢速查询日志输出目标”)。
Flushes status indicators.刷新状态指示器。
This operation requires the 此操作需要FLUSH_STATUS or RELOAD privilege.FLUSH_STATUS权限或RELOAD权限。
This operation adds the session status from all active sessions to the global status variables, resets the status of all active sessions, and resets account, host, and user status values aggregated from disconnected sessions. 此操作将所有活动会话的会话状态添加到全局状态变量中,重置所有活动会话的状态,并重置从断开连接的会话聚合的帐户、主机和用户状态值。See Section 27.12.15, “Performance Schema Status Variable Tables”. 请参阅第27.12.15节,“性能模式状态变量表”。This information may be of use when debugging a query. 调试查询时,此信息可能有用。See Section 1.6, “How to Report Bugs or Problems”.请参阅第1.6节,“如何报告错误或问题”。
Resets all per-hour user resource indicators to zero.将所有每小时用户资源指标重置为零。
This operation requires the FLUSH_USER_RESOURCES or RELOAD privilege.
Resetting resource indicators enables clients that have reached their hourly connection, query, or update limits to resume activity immediately. 重置资源指示器使达到每小时连接、查询或更新限制的客户端能够立即恢复活动。FLUSH USER_RESOURCES does not apply to the limit on maximum simultaneous connections that is controlled by the max_user_connections system variable. See Section 6.2.20, “Setting Account Resource Limits”.请参阅第6.2.20节,“设置账户资源限制”。
FLUSH TABLES flushes tables, and, depending on the variant used, acquires locks. FLUSH TABLES刷新表,并根据使用的变量获取锁。Any TABLES variant used in a FLUSH statement must be the only option used. FLUSH TABLE is a synonym for FLUSH TABLES.
The descriptions here that indicate tables are flushed by closing them apply differently for 这里的描述表明通过关闭表来刷新表,这与InnoDB, which flushes table contents to disk but leaves them open. InnoDB不同,InnoDB将表内容刷新到磁盘,但保持打开状态。This still permits table files to be copied while the tables are open, as long as other activity does not modify them.这仍然允许在表打开时复制表文件,只要其他活动不修改它们。
Closes all open tables, forces all tables in use to be closed, and flushes the prepared statement cache.关闭所有打开的表,强制关闭所有正在使用的表,并刷新准备好的语句缓存。
This operation requires the 此操作需要FLUSH_TABLES or RELOAD privilege.FLUSH_TABLES或RELOAD权限。
For information about prepared statement caching, see Section 8.10.3, “Caching of Prepared Statements and Stored Programs”.有关预处理语句缓存的信息,请参阅第8.10.3节,“预处理语句和存储程序的缓存”。
FLUSH TABLES is not permitted when there is an active LOCK TABLES ... READ. To flush and lock tables, use FLUSH TABLES instead.tbl_name ... WITH READ LOCK
FLUSH TABLES tbl_name [, tbl_name] ...
With a list of one or more comma-separated table names, this operation is like FLUSH TABLES with no names except that the server flushes only the named tables. If a named table does not exist, no error occurs.
This operation requires the FLUSH_TABLES or RELOAD privilege.
Closes all open tables and locks all tables for all databases with a global read lock.关闭所有打开的表,并使用全局读锁锁定所有数据库的所有表。
This operation requires the FLUSH_TABLES or RELOAD privilege.
This operation is a very convenient way to get backups if you have a file system such as Veritas or ZFS that can take snapshots in time. 如果您的文件系统(如Veritas或ZFS)可以及时拍摄快照,则此操作是获取备份的一种非常方便的方法。Use UNLOCK TABLES to release the lock.
FLUSH TABLES WITH READ LOCK acquires a global read lock rather than table locks, so it is not subject to the same behavior as LOCK TABLES and UNLOCK TABLES with respect to table locking and implicit commits:
UNLOCK TABLES implicitly commits any active transaction only if any tables currently have been locked with LOCK TABLES. The commit does not occur for UNLOCK TABLES following FLUSH TABLES WITH READ LOCK because the latter statement does not acquire table locks.
Beginning a transaction causes table locks acquired with LOCK TABLES to be released, as though you had executed UNLOCK TABLES. Beginning a transaction does not release a global read lock acquired with FLUSH TABLES WITH READ LOCK.
FLUSH TABLES WITH READ LOCK does not prevent the server from inserting rows into the log tables (see Section 5.4.1, “Selecting General Query Log and Slow Query Log Output Destinations”).
FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK
Flushes and acquires read locks for the named tables.刷新并获取命名表的读锁。
This operation requires the 此操作需要FLUSH_TABLES or RELOAD privilege. FLUSH_TABLES权限或RELOAD权限。Because it acquires table locks, it also requires the 因为它获取表锁,所以它还需要每个表的LOCK TABLES privilege for each table.LOCK TABLES权限。
The operation first acquires exclusive metadata locks for the tables, so it waits for transactions that have those tables open to complete. 该操作首先获取表的独占元数据锁,因此它会等待打开这些表的事务完成。Then the operation flushes the tables from the table cache, reopens the tables, acquires table locks (like 然后,该操作从表缓存中刷新表,重新打开表,获取表锁(如LOCK TABLES ... READ), and downgrades the metadata locks from exclusive to shared. LOCK TABLES ... READ),并将元数据锁从独占降级为共享。After the operation acquires locks and downgrades the metadata locks, other sessions can read but not modify the tables.操作获取锁并降级元数据锁后,其他会话可以读取但不能修改表。
This operation applies only to existing base (non-此操作仅适用于现有的基本表(非TEMPORARY) tables. TEMPORARY表)。If a name refers to a base table, that table is used. 如果一个名称引用一个基表,则使用该表。If it refers to a 如果它引用了一个TEMPORARY table, it is ignored. TEMPORARY表,它将被忽略。If a name applies to a view, an 如果某个名称应用于某个视图,则会发生ER_WRONG_OBJECT error occurs. ER_WRONG_OBJECT错误。Otherwise, an 否则,会出现ER_NO_SUCH_TABLE error occurs.ER_NO_SUCH_TABLE错误。
Use UNLOCK TABLES to release the locks, LOCK TABLES to release the locks and acquire other locks, or START TRANSACTION to release the locks and begin a new transaction.
This 此FLUSH TABLES variant enables tables to be flushed and locked in a single operation. FLUSH TABLES变体允许在一次操作中刷新和锁定表。It provides a workaround for the restriction that FLUSH TABLES is not permitted when there is an active LOCK TABLES ... READ.
This operation does not perform an implicit UNLOCK TABLES, so an error results if you perform the operation while there is any active LOCK TABLES or use it a second time without first releasing the locks acquired.
If a flushed table was opened with 如果使用HANDLER, the handler is implicitly flushed and loses its position.HANDLER打开刷新的表,则该处理程序将被隐式刷新并失去其位置。
FLUSH TABLES tbl_name [, tbl_name] ... FOR EXPORT
This 此FLUSH TABLES variant applies to InnoDB tables. FLUSH TABLES变体适用于InnoDB表。It ensures that changes to the named tables have been flushed to disk so that binary table copies can be made while the server is running.它确保对命名表的更改已刷新到磁盘,以便在服务器运行时进行二进制表拷贝。
This operation requires the 此操作需要FLUSH_TABLES or RELOAD privilege. FLUSH_TABLES权限或RELOAD权限。Because it acquires locks on tables in preparation for exporting them, it also requires the 因为它获取表上的锁以准备导出它们,所以它还需要LOCK TABLES and SELECT privileges for each table.LOCK TABLES权限和每个表的SELECT权限。
The operation works like this:操作如下:
It acquires shared metadata locks for the named tables. 它获取命名表的共享元数据锁。The operation blocks as long as other sessions have active transactions that have modified those tables or hold table locks for them. 只要其他会话具有已修改这些表或为其持有表锁的活动事务,操作就会被阻止。When the locks have been acquired, the operation blocks transactions that attempt to update the tables, while permitting read-only operations to continue.获取锁后,该操作会阻止尝试更新表的事务,同时允许只读操作继续。
It checks whether all storage engines for the tables support 它检查表的所有存储引擎是否支持FOR EXPORT. FOR EXPORT导出。If any do not, an 如果没有,则会发生ER_ILLEGAL_HA error occurs and the operation fails.ER_ILLEGAL_HA错误,操作失败。
The operation notifies the storage engine for each table to make the table ready for export. 该操作会通知每个表的存储引擎,使该表准备好导出。The storage engine must ensure that any pending changes are written to disk.存储引擎必须确保将任何挂起的更改写入磁盘。
The operation puts the session in lock-tables mode so that the metadata locks acquired earlier are not released when the 该操作将会话置于锁表模式,以便在FOR EXPORT operation completes.FOR EXPORT操作完成时不会释放之前获取的元数据锁。
This operation applies only to existing base (non-TEMPORARY) tables. If a name refers to a base table, that table is used. If it refers to a TEMPORARY table, it is ignored. If a name applies to a view, an ER_WRONG_OBJECT error occurs. Otherwise, an ER_NO_SUCH_TABLE error occurs.
InnoDB supports FOR EXPORT for tables that have their own .ibd file file (that is, tables created with the innodb_file_per_table setting enabled). InnoDB ensures when notified by the FOR EXPORT operation that any changes have been flushed to disk. This permits a binary copy of table contents to be made while the FOR EXPORT operation is in effect because the .ibd file is transaction consistent and can be copied while the server is running. FOR EXPORT does not apply to InnoDB system tablespace files, or to InnoDB tables that have FULLTEXT indexes.
分区FLUSH TABLES ...FOR EXPORT is supported for partitioned InnoDB tables.InnoDB表支持FLUSH TABLES ...FOR EXPORT。
When notified by 当收到FOR EXPORT, InnoDB writes to disk certain kinds of data that is normally held in memory or in separate disk buffers outside the tablespace files. FOR EXPORT通知时,InnoDB会将某些类型的数据写入磁盘,这些数据通常保存在内存中或表空间文件之外的单独磁盘缓冲区中。For each table, 对于每个表,InnoDB also produces a file named in the same database directory as the table. table_name.cfgInnoDB还生成一个名为table_name.cfg的文件,与表位于同一数据库目录中。The 这个.cfg file contains metadata needed to reimport the tablespace files later, into the same or different server..cfg文件包含稍后将表空间文件重新导入相同或不同服务器所需的元数据。
When the FOR EXPORT operation completes, InnoDB has flushed all dirty pages to the table data files. FOR EXPORT操作完成后,InnoDB已将所有脏页刷新到表数据文件中。Any change buffer entries are merged prior to flushing. 任何更改缓冲区条目都会在刷新之前合并。At this point, the tables are locked and quiescent: The tables are in a transactionally consistent state on disk and you can copy the 此时,表被锁定且处于静止状态:表在磁盘上处于事务一致状态,您可以复制.ibd tablespace files along with the corresponding .cfg files to get a consistent snapshot of those tables..ibd表空间文件以及相应的.cfg文件以获得这些表的一致快照。
For the procedure to reimport the copied table data into a MySQL instance, see Section 15.6.1.3, “Importing InnoDB Tables”.有关将复制的表数据重新导入MySQL实例的过程,请参阅第15.6.1.3节,“导入InnoDB表”。
After you are done with the tables, use 处理完表后,使用UNLOCK TABLES to release the locks, LOCK TABLES to release the locks and acquire other locks, or START TRANSACTION to release the locks and begin a new transaction.UNLOCK TABLES释放锁,LOCK TABLES释放锁并获取其他锁,或者启动TRANSACTION释放锁并开始新的事务。
While any of these statements is in effect within the session, attempts to use 虽然这些语句中的任何一条在会话中有效,但是尝试使用FLUSH TABLES ... FOR EXPORT produce an error:FLUSH TABLES ... FOR EXPORT生成一个错误:
FLUSH TABLES ... WITH READ LOCK FLUSH TABLES ... FOR EXPORT LOCK TABLES ... READ LOCK TABLES ... WRITE
While 虽然FLUSH TABLES ... FOR EXPORT is in effect within the session, attempts to use any of these statements produce an error:FLUSH TABLES ... FOR EXPORT在会话中有效,但是尝试使用以下任何语句都会产生错误:
FLUSH TABLES WITH READ LOCK FLUSH TABLES ... WITH READ LOCK FLUSH TABLES ... FOR EXPORT