MySQL :: MySQL 8.4 Reference Manual :: 15.7.8.3 FLUSH Statement (original) (raw)

15.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
  | LOGS
  | PRIVILEGES
  | OPTIMIZER_COSTS
  | RELAY LOGS [FOR CHANNEL channel]
  | SLOW LOGS
  | STATUS
  | USER_RESOURCES
}

tables_option: {
    table_synonym
  | table_synonym tbl_name [, tbl_name] ...
  | table_synonym WITH READ LOCK
  | table_synonym tbl_name [, tbl_name] ... WITH READ LOCK
  | table_synonym tbl_name [, tbl_name] ... FOR EXPORT
}

table_synonym: {
    TABLE
  | TABLES
}

The FLUSH statement has several variant forms that clear or reload various internal caches, flush tables, or acquire locks. EachFLUSH operation requires the privileges indicated in its description.

By default, the server writesFLUSH statements to the binary log so that they replicate to replicas. To suppress logging, specify the optional NO_WRITE_TO_BINLOG keyword or its alias LOCAL.

The FLUSH statement causes an implicit commit. See Section 15.3.3, “Statements That Cause an Implicit Commit”.

The mysqladmin utility provides a command-line interface to some flush operations, using commands such as flush-logs,flush-privileges,flush-status, andflush-tables. SeeSection 6.5.2, “mysqladmin — A MySQL Server Administration Program”.

Sending a SIGHUP orSIGUSR1 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. 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. SeeSection 6.10, “Unix Signal Handling in MySQL”.

The RESET statement is similar toFLUSH. SeeSection 15.7.8.6, “RESET Statement”, for information about usingRESET with replication.

The following list describes the permittedFLUSH statement_flushoption_ values. For descriptions of the permitted tablesoption values, see FLUSH TABLES Syntax.

FLUSH BINARY LOGS  
FLUSH ENGINE LOGS  
FLUSH ERROR LOGS  
FLUSH GENERAL LOGS  
FLUSH RELAY LOGS  
FLUSH SLOW LOGS  
FLUSH TABLES Syntax

FLUSH TABLES flushes tables, and, depending on the variant used, acquires locks. AnyTABLES variant used in aFLUSH 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. This still permits table files to be copied while the tables are open, as long as other activity does not modify them.

FLUSH TABLES ... WITH READ LOCK  
FLUSH TABLES ... FOR EXPORT  
LOCK TABLES ... READ  
LOCK TABLES ... WRITE  

WhileFLUSH TABLES ... FOR EXPORT is in effect within the session, attempts to use any of these statements produce an error:

FLUSH TABLES WITH READ LOCK  
FLUSH TABLES ... WITH READ LOCK  
FLUSH TABLES ... FOR EXPORT