FLUSH [LOCAL | NO_WRITE_TO_BINLOG] flush_option [,flush_option] ...
You should use the FLUSH command if you want to clear some of the internal caches MySQL uses. To execute FLUSH, you must have the RELOAD privilege.
flush_option can be any of the following:
Option | Description |
HOSTS | Empties the host cache tables. You should flush the host tables if some of your hosts change IP number or if you get the error message Host ... is blocked. When more than max_connect_errors errors occur in a row for a given host while connection to the MySQL server, MySQL assumes something is wrong and blocks the host from further connection requests. Flushing the host tables allows the host to attempt to connect again. See Blocked host. You can start mysqld with -O max_connect_errors=999999999 to avoid this error message. |
DES_KEY_FILE | Reloads the DES keys from the file that was specified with the --des-key-file option at server startup time. |
LOGS | Closes and reopens all log files. If you have specified an update log file or a binary log file without an extension, the extension number of the log file will be incremented by one relative to the previous file. If you have used an extension in the file name, MySQL will close and reopen the update log file. See Update log. This is the same thing as sending the SIGHUP signal to the mysqld server. |
PRIVILEGES | Reloads the privileges from the grant tables in the mysql database. |
QUERY CACHE | Defragment the query cache to better utilize its memory. This command will not remove any queries from the cache, unlike RESET QUERY CACHE. |
TABLES | Closes all open tables and force all tables in use to be closed. This also flushes the query cache. |
[TABLE | TABLES] tbl_name [,tbl_name...] | Flushes only the given tables. |
TABLES WITH READ LOCK | Closes all open tables and locks all tables for all databases with a read lock until you execute UNLOCK TABLES. This is very convenient way to get backups if you have a filesystem, like Veritas, that can take snapshots in time. |
STATUS | Resets most status variables to zero. This is something one should only use when debugging a query. See Bug reports. |
USER_RESOURCES | Resets all user resources to zero. This will enable blocked users to login again. See User resources. |
Before MySQL 4.1.1, FLUSH commands are not written to the binary log. Since MySQL 4.1.1 they are written to the binary log unless the optional NO_WRITE_TO_BINLOG keyword (or its alias LOCAL) was used, or unless the command contained one of these arguments: LOGS, MASTER, SLAVE, TABLES WITH READ LOCK, because any of these arguments may cause problems if replicated to a slave.
You can also access some of the commands shown above with the mysqladmin utility, using the flush-hosts, flush-logs, flush-privileges, flush-status or flush-tables commands.
Take also a look at the RESET command used with replication. See RESET.
KILL thread_id KILL CONNECTION thread_id KILL QUERY thread_id
Each connection to mysqld runs in a separate thread. You can see which threads are running with the SHOW PROCESSLIST command and kill a thread with the KILL thread_id command.
As of MySQL 5.0.0, KILL allows the optional CONNECTION or QUERY modifiers:
KILL CONNECTION is the same as KILL with no modifier: It terminates the connection associated with the given thread_id.
KILL QUERY terminates the statement that the connection is executing, but leaves the connection intact.
If you have the PROCESS privilege, you can see all threads. If you have the SUPER privilege, you can kill all threads and statements. Otherwise, you can only see and kill your own threads and statements.
You can also use the mysqladmin processlist and mysqladmin kill commands to examine and kill threads.
Note: You currently cannot use KILL with the Embedded MySQL Server library, because the embedded server merely runs inside the threads of the host application, it does not create connection threads of its own.
When you do a KILL, a thread-specific kill flag is set for the thread.
In most cases it may take some time for the thread to die, as the kill flag is only checked at specific intervals.
In SELECT, ORDER BY and GROUP BY loops, the flag is checked after reading a block of rows. If the kill flag is set, the statement is aborted.
When doing an ALTER TABLE the kill flag is checked before each block of rows are read from the original table. If the kill flag was set the command is aborted and the temporary table is deleted.
When doing an UPDATE or DELETE, the kill flag is checked after each block read and after each updated or deleted row. If the kill flag is set, the statement is aborted. Note that if you are not using transactions, the changes will not be rolled back!
GET_LOCK() will abort with NULL.
An INSERT DELAYED thread will quickly flush all rows it has in memory and die.
If the thread is in the table lock handler (state: Locked), the table lock will be quickly aborted.
If the thread is waiting for free disk space in a write call, the write is aborted with an disk full error message.
PURGE {MASTER|BINARY} LOGS TO binlog_name PURGE {MASTER|BINARY} LOGS BEFORE date
This command is used to delete all binary logs strictly prior to the specified binlog or date. See Replication Master SQL.
PURGE BINARY LOGS is available as a synonym for PURGE MASTER LOGS as of MySQL 4.1.1.
RESET reset_option [,reset_option] ...
The RESET command is used to clear things. It also acts as an stronger version of the FLUSH command. See FLUSH.
To execute RESET, you must have the RELOAD privilege.
Option | Description |
MASTER | Deletes all binary logs listed in the index file, resetting the binlog index file to be empty. Previously named FLUSH MASTER. See Replication Master SQL. |
SLAVE | Makes the slave forget its replication position in the master binlogs. Previously named FLUSH SLAVE. See Replication Slave SQL. |
QUERY CACHE | Removes all query results from the query cache. |