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” &
done
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:
#!/bin/bash
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;
done
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.