KILL

Description

The KILL statement terminates a running query or process.

Info

Terminating a process or query may result in the loss of unsaved data; terminating a running query may consume system resources and affect other running queries.

Syntax

1. > KILL [CONNECTION | QUERY] processlist_id

Explanations

process_id refers to the identifier of the process or query to be terminated. process_id is the connection identifier if the CONNECTION keyword is used, and process_id is the query identifier if the QUERY keyword is used.

Examples

1. select connection_id();
2. +-----------------+
3. | connection_id() |
4. +-----------------+
5. |            1008 |
6. +-----------------+
7. 1 row in set (0.00 sec)

9. -- Terminate query process
10. mysql> kill query 1008;
11. Query OK, 0 rows affected (0.00 sec)

13. -- Terminate the connection process
14. mysql> kill connection 1008;
15. Query OK, 0 rows affected (0.00 sec)

17. -- Test for disconnection
18. mysql> show databases;
19. ERROR 2013 (HY000): Lost connection to MySQL server during query
20. No connection. Trying to reconnect...
21. Connection id:    1180
22. -- The connection has been disconnected, and the service has started to reconnect