13.7.8.3 FLUSH Statement语句

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操作都需要其说明中指定的权限。

Note注意

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. 但是,只要存储过程不是从存储函数或触发器调用的,就可以在存储过程中使用FLUSHSee 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

Note注意

FLUSH LOGS, FLUSH BINARY LOGS, FLUSH TABLES WITH READ LOCK (with or without a table list), and FLUSH TABLES tbl_name ... FOR EXPORT are not written to the binary log in any case because they would cause problems if replicated to a replica.

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语句类似于FLUSHSee Section 13.7.8.6, “RESET Statement”, for information about using RESET with replication.请参阅第13.7.8.6节,“RESET语句”,以了解有关在复制中使用RESET的信息。

The following list describes the permitted FLUSH statement flush_option values. For descriptions of the permitted tables_option values, see FLUSH TABLES Syntax.

FLUSH TABLES Syntax刷新表语法

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.

Note注意

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.这仍然允许在表打开时复制表文件,只要其他活动不修改它们。