Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do you kill a mass of MySQL queries? Here is a good approach:

mysql> SELECT concat('KILL ',id,';') FROM information_schema.processlist WHERE user='root' INTO OUTFILE '/tmp/a.txt';
mysql> source /tmp/a.txt;

Any others besides clicking them to death in MySQL Administrator GUI?

share|improve this question
Use the code tags - that's what they're for. – Artem Russakovskii May 22 '09 at 18:09
Also, the solution you linked to has plenty of other solutions in the comments. You should read them. – Artem Russakovskii May 22 '09 at 18:10
up vote 6 down vote accepted

To crib the best comments from Percona's take on this:

Comment 4: Robert Wultsch

I prefer the following as it will kill them in a multi threaded manner… (sometimes killing a single query can take a while)

for i in $(mysql -uroot -pPASS -e ’show processlist’ | grep ’search_term’ | awk ‘{print $1}’); do

mysql -uroot -pPASS -e “kill $i” &


Comment 8: Shlomi Noach

An INFORMATION_SCHEMA.PROCESSLIST stored procedure which is a bit verbose to copy.

Comment 16: Bryan

If information_schema.processlist doesn’t exist on your version of MySQL, this works in a linux script:


for each in `mysqladmin -u root -prootpwd processlist | awk 
‘{print $2, $4, $8}’ | grep $dbname | grep $dbuser | awk ‘{print $1}’`;

do mysqladmin -u root -prootpwd kill $each;


Comment 21: Andrew Watson

I do this:

mysqladmin proc | grep Sleep | sort -r -n -k6 | awk {’print $1; ‘} | xargs mysqladmin kill

or something to that effect…

As Dan C mentions in his answer to this question, pruning SELECTS is significantly safer than killing write commands mid-flow, as you may lose data integrity and/or foreign keys.

share|improve this answer

An alternative solution is to use an approach that Digg describe, which is to automatically prune any SELECT queries which take longer than an allotted period of time to complete. Generally speaking you only want to prune SELECT queries because they are read-only and shouldn't affect the data integrity of your application.

Two such utilities that you can use to automate this are and mkill which is part of a package called mtop.

share|improve this answer

I used it to kill all sleeping queries on MySQL 5.5 database server:

mysql -e "show full processlist;" -ss | grep Sleep | awk '{print "KILL "$1";"}' | mysql
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.