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?
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)
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:
Comment 21: Andrew Watson
I do this:
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.
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 dbmon.pl and mkill which is part of a package called mtop.
I used it to kill all sleeping queries on MySQL 5.5 database server:
The easiest is to kill them from the shell, e.g.
If there is still a problem, check the details by the following query:
From MySQL, try the following code based on the post by @Shlomi, you can create a stored procedure using server cursor, for example:
There is also an old script called
mypgrep.py
by Google.