KILL [CONNECTION | QUERY] processlist_id
Each connection to mysqld runs in a separate
thread. You can kill a thread with the KILL
statement.
processlist_id
Thread processlist identifiers can be determined from the
ID column of the
INFORMATION_SCHEMA
PROCESSLIST table, the
Id column of SHOW
PROCESSLIST output, and the
PROCESSLIST_ID column of the Performance
Schema threads table. The value for
the current thread is returned by the
CONNECTION_ID() function.
KILL permits an optional
CONNECTION or QUERY
modifier:
KILL CONNECTIONis the same asKILLwith no modifier: It terminates the connection associated with the givenprocesslist_id, after terminating any statement the connection is executing.KILL QUERYterminates the statement the connection is currently executing, but leaves the connection itself intact.
The ability to see which threads are available to be killed
depends on the PROCESS privilege:
The ability to kill threads and statements depends on the
CONNECTION_ADMIN privilege and
the deprecated SUPER privilege:
Without
CONNECTION_ADMINorSUPER, you can kill only your own threads and statements.With
CONNECTION_ADMINorSUPER, you can kill all threads and statements, except that to affect a thread or statement that is executing with theSYSTEM_USERprivilege, your own session must additionally have theSYSTEM_USERprivilege.
You can also use the mysqladmin processlist and mysqladmin kill commands to examine and kill threads.
When you use KILL, a
thread-specific kill flag is set for the thread. In most cases,
it might take some time for the thread to die because the kill
flag is checked only at specific intervals:
During
SELECToperations, forORDER BYandGROUP BYloops, the flag is checked after reading a block of rows. If the kill flag is set, the statement is aborted.ALTER TABLEoperations that make a table copy check the kill flag periodically for each few copied rows read from the original table. If the kill flag was set, the statement is aborted and the temporary table is deleted.The
KILLstatement returns without waiting for confirmation, but the kill flag check aborts the operation within a reasonably small amount of time. Aborting the operation to perform any necessary cleanup also takes some time.During
UPDATEorDELETEoperations, 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. If you are not using transactions, the changes are not rolled back.GET_LOCK()aborts and returnsNULL.If the thread is in the table lock handler (state:
Locked), the table lock is quickly aborted.If the thread is waiting for free disk space in a write call, the write is aborted with a “disk full” error message.
EXPLAIN ANALYZEaborts and prints the first row of output.
Killing a REPAIR TABLE or
OPTIMIZE TABLE operation on a
MyISAM table results in a table that is
corrupted and unusable. Any reads or writes to such a table
fail until you optimize or repair it again (without
interruption).