Kill running process

By | February 18, 2013

Howto kill a process in Mysql

If you have a “hanging” process in MySQL and want to kill it, you use show processlist to identify the process you want to kill get get the id. Then a simple kill ID will do the job.

mysql> show processlist;

+-----+------+-----------+---------+---------+-------+-------+------------------+
| Id  | User | Host      | db      | Command | Time  | State | Info             |
+-----+------+-----------+---------+---------+-------+-------+------------------+
| 882 | user | localhost | test    | Sleep   | 27111 |       | NULL             |
| 893 | user | localhost | test    | Sleep   |   453 |       | NULL             |
| 901 | user | localhost | NULL    | Query   |     0 | NULL  | show processlist |
+-----+------+-----------+---------+---------+-------+-------+------------------+
3 rows in set (0.00 sec)

mysql> kill 882

The same can be done using mysqladmin form the command line:

    [root@host]# mysqladmin processlist
    +-----+------+-----------+---------+---------+------+-------+------------------+
    | Id  | User | Host      | db      | Command | Time | State | Info             |
    +-----+------+-----------+---------+---------+------+-------+------------------+
    | 882 | prog | localhost | test    | Sleep   | 2676 |       |                  |
    | 893 | prog | localhost |         | Sleep   | 1823 |       |                  |
    | 903 | root | localhost |         | Query   | 0    |       | show processlist |
    +-----+------+-----------+---------+---------+------+-------+------------------+
    [root@host]#

    [root@host]# mysqladmin kill 882

Link to the MySQL documentation

KILL Syntax
SHOW PROCESSLIST Syntax