4

I want to kill all the MySQL processes in the process list. Is there any way to do that?

# mysqladmin -u root -p processlist
Enter password: 
+------+----------------------+---------------------+----+---------+------+-------+------------------+
| Id   | User                 | Host                | db | Command | Time | State | Info             |
+------+----------------------+---------------------+----+---------+------+-------+------------------+
| 1908 | unauthenticated user | 192.168.1.103:46046 |    | Connect |      | login |                  |
| 1909 | unauthenticated user | 192.168.1.103:46047 |    | Connect |      | login |                  |
| 1910 | unauthenticated user | 192.168.1.103:46048 |    | Connect |      | login |                  |
| 1914 | unauthenticated user | 192.168.1.103:46049 |    | Connect |      | login |                  |
| 1946 | unauthenticated user | 192.168.1.103:46076 |    | Connect |      | login |                  |
| 1954 | unauthenticated user | 192.168.1.103:46078 |    | Connect |      | login |                  |
| 2015 | root                 | localhost           |    | Query   | 0    |       | show processlist |
+------+----------------------+---------------------+----+---------+------+-------+------------------+
HopelessN00b
  • 54,273
billyduc
  • 1,637

5 Answers5

4

Looks like this might be covered at Bulk or mass killing misbehaving MySQL queries

Yancy
  • 89
2

Stop/start of MySQL instance is not an answer. In most cases it can take quite a lot of time and impact your production. You should just KILL such queries.

Two interesting articles:

How to selectively kill queries in MySQL?

and:

Why do threads sometimes stay in ‘killed’ state in MySQL?

Sasha
  • 29
0

You can achieve this with a shell script:

#!/bin/bash

# Get the processlist and save it in a file
mysqladmin -u root -p"your password" processlist > fullproce

# Get the process ids of the processes in the "Sleep" state and save them in id.
# Adjust the grep to match the processes you want to kill.
cat fullproce |grep Sleep |awk -F " " '{print $2}' > id

for todos_id in `cat ./id`
do
  # Kill each id identified earlier.
  mysqladmin -u root -p"your password" KILL $todos_id ;
done

# Remove files
rm  fullproce
rm id
Ladadadada
  • 27,207
0

Quickest way is just to restart MySQL. Otherwise you'll need to kill off each running process one by one (there's no killall in mysqladmin).

womble
  • 98,245
-1

This shell command may help to kill all sleep processes:

mysqladmin proc | grep Sleep | awk '{print $2}' | xargs -L1 mysqladmin kill 
kenorb
  • 7,125