How do I kill all the processes in MySQL “show processlist”?


We can kill the processes with the help of the ‘kill’ command. However, you need to kill those processes one by one, since MySQL does not have any massive kill command.

To check how many processes exist, use ‘show processlist’

mysql> show processlist;

The following is the output.

+----+-----------------+-----------------+------+---------+------+------------------------+------------------+
| Id | User            | Host            | db   | Command | Time | State                  | Info             |
+----+-----------------+-----------------+------+---------+------+------------------------+------------------+
|  4 | event_scheduler | localhost       | NULL | Daemon  | 7986 | Waiting on empty queue | NULL             |
|  8 | root            | localhost:65180 | test | Query   |    0 | starting               | show processlist |
+----+-----------------+-----------------+------+---------+------+------------------------+------------------+
2 rows in set (0.00 sec)

To kill a process which have been active for more than 10 seconds, the following is the query. Here, we are killing a process with Id “4”

mysql> select concat('kill ',4,';')
   -> from information_schema.processlist
   ->  where TIME > 10;

Here is the output.

+-----------------------+once;

| concat('kill ',4,';') |
+-----------------------+
| kill 4;               |
+-----------------------+
1 row in set (0.00 sec)

As an alterbative, you can still try the following MySQL query to kill all the processes.

mysql -e "show full processlist;" -ss | awk '{print "KILL "$1";"}'| mysql
raja
Published on 21-Nov-2018 12:32:12
Advertisements