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)
  8. -- Terminate query process
  9. mysql> kill query 1008;
  10. Query OK, 0 rows affected (0.00 sec)
  11. -- Terminate the connection process
  12. mysql> kill connection 1008;
  13. Query OK, 0 rows affected (0.00 sec)
  14. -- Test for disconnection
  15. mysql> show databases;
  16. ERROR 2013 (HY000): Lost connection to MySQL server during query
  17. No connection. Trying to reconnect...
  18. Connection id: 1180
  19. -- The connection has been disconnected, and the service has started to reconnect