Killing MySQL Processes

Once in a while you might face problems related to MySQL being not responding. Most of the time it’s due to large database size or you’re running a select query on an un-indexed table. Instead of waiting for the process to complete (which may take hours), you can cancel the stalling processes using the following method.

First, open up another MySQL session and call the following query:

SHOW PROCESSLIST;

Next, you will see results like this:

+—-+—————–+———–+——+———+——+————————+——————+———-+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+—-+—————–+———–+——+———+——+————————+——————+———-+
| 254772 | event_scheduler | localhost | NULL | Daemon | 2693 | Waiting on empty queue | NULL | 0.000 |
| 435342 | root | localhost | NULL | Query | 0 | Table lock | SHOW PROCESSLIST | 0.000 |
+—-+—————–+———–+——+———+——+————————+——————+———-+

Look for the ID of the query which you wish to terminate and use it in the following query, for example:

KILL 435342;

That’s it, the process will then be terminated by MySQL. Hope it helps.

Leave a Reply

Your email address will not be published. Required fields are marked *