- MySQL 5.1 Reference Manual :: 12 SQL Statement Syntax :: 12.4 Database Administration Statements :: 12.4.6 Other Administrative Statements :: 12.4.6.4 KILL Syntax
-
- MySQL 5.1 Reference Manual
- Preface, Notes, Licenses
- 1 General Information
- 2 Installing and Upgrading MySQL
- 3 Tutorial
- 4 MySQL Programs
- 5 MySQL Server Administration
- 6 Backup and Recovery
- 7 Optimization
- 8 Language Structure
- 9 Internationalization and Localization
- 10 Data Types
- 11 Functions and Operators
- 12 SQL Statement Syntax
- 13 Storage Engines
- 14 High Availability and Scalability
- 15 MySQL Enterprise Monitor
- 16 Replication
- 17 MySQL Cluster NDB 6.X/7.X
- 18 Partitioning
- 19 Stored Programs and Views
- 20 INFORMATION_SCHEMA Tables
- 21 Connectors and APIs
- 22 Extending MySQL
- A MySQL 5.1 Frequently Asked Questions
- B Errors, Error Codes, and Common Problems
- C MySQL Change History
- D Restrictions and Limits
- Index
- Standard Index
- C Function Index
- Command Index
- Function Index
- INFORMATION_SCHEMA Index
- Transaction Isolation Level Index
- JOIN Types Index
- Operator Index
- Option Index
- Privileges Index
- SQL Modes Index
- Status Variable Index
- Statement/Syntax Index
- System Variable Index
KILL [CONNECTION | QUERY]
thread_id
Each connection to mysqld runs in a separate thread. You can see which threads are running with the
SHOW PROCESSLIST
statement and kill a thread with theKILL
statement.thread_id
KILL
allows the optionalCONNECTION
orQUERY
modifier:KILL CONNECTION
is the same asKILL
with no modifier: It terminates the connection associated with the giventhread_id
.KILL QUERY
terminates the statement that the connection is currently executing, but leaves the connection itself intact.
If you have the
PROCESS
privilege, you can see all threads. If you have theSUPER
privilege, you can kill all threads and statements. Otherwise, you can see and kill only your own threads and statements.You can also use the mysqladmin processlist and mysqladmin kill commands to examine and kill threads.
Note
You 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 any connection threads of its own.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:In
SELECT
,ORDER BY
andGROUP BY
loops, the flag is checked after reading a block of rows. If the kill flag is set, the statement is aborted.During
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 statement is aborted and the temporary table is deleted.During
UPDATE
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. Note that if you are not using transactions, the changes are not rolled back.GET_LOCK()
aborts and returnsNULL
.An
INSERT DELAYED
thread quickly flushes (inserts) all rows it has in memory and then terminates.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.
Warning
Killing a
REPAIR 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).