Documentation Home
MySQL 9.3 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 261.1Kb
Man Pages (Zip) - 368.3Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


15.7.8.4 KILL Statement

KILL [CONNECTION | QUERY]processlist_id

Each connection tomysqld runs in a separate thread. You can kill a thread with theKILLprocesslist_id statement.

Thread processlist identifiers can be determined from theID column of theINFORMATION_SCHEMAPROCESSLIST table, theId column ofSHOW PROCESSLIST output, and thePROCESSLIST_ID column of the Performance Schemathreads table. The value for the current thread is returned by theCONNECTION_ID() function.

KILL permits an optionalCONNECTION orQUERY modifier:

  • KILL CONNECTION is the same asKILL with no modifier: It terminates the connection associated with the givenprocesslist_id, after terminating any statement the connection is executing.

  • KILL QUERY terminates 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 thePROCESS privilege:

  • WithoutPROCESS, you can see only your own threads.

  • WithPROCESS, you can see all threads.

The ability to kill threads and statements depends on theCONNECTION_ADMIN privilege and the deprecatedSUPER privilege:

You can also use themysqladmin processlist andmysqladmin kill commands to examine and kill threads.

When you useKILL, 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:

  • DuringSELECT operations, forORDER BY andGROUP BY loops, the flag is checked after reading a block of rows. If the kill flag is set, the statement is aborted.

  • ALTER TABLE operations 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.

    TheKILL statement 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.

  • DuringUPDATE orDELETE operations, 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 adisk full error message.

  • EXPLAIN ANALYZE aborts and prints the first row of output.

Warning

Killing aREPAIR TABLE orOPTIMIZE TABLE operation on aMyISAM 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).