KILL
Grammar Description
The KILL statement is used to terminate a running query or process.
Info
Terminating a process or query may result in the loss of unsaved data; terminating a running query may take up system resources and may affect other running queries.
Grammar Structure
> KILL [CONNECTION | QUERY] process_id;
Syntax Explanation
process_id refers to the identifier of the process or query to be terminated. If the CONNECTION keyword is used, then process_id is the connection identifier, and if the QUERY keyword is used, then process_id is the query identifier.
Example
select connection_id();
+-----------------------+
| connection_id() |
+-----------------------+
| 1008 |
+-----------------------+
1 row in set (0.00 sec)
-- Terminate the query process
mysql> kill query 1008;
Query OK, 0 rows affected (0.00 sec)
-- Terminate the connection process
mysql> kill connection 1008;
Query OK, 0 rows affected (0.00 sec)
-- Test whether the connection is disconnected
mysql> show databases;
ERROR 2013 (HY000): Lost connection to MySQL server during query
No connection. Trying to reconnect...
Connection id: 1180
-- The connection has been disconnected and the service has started to reconnect