MySQL kill all queries by user

Here’s a dirty command-line utility that kills all MySQL queries originated by a given user:

1
mysql -u'YOUR_MYSQL_USER' -p'YOUR_MYSQL_PASSWORD' -h'YOUR_MYSQL_HOST' -e "select ID from information_schema.processlist where user='YOUR_MYSQL_USER';" | sed '1d' | awk '{print "kill ", $1, ";"}' | xargs -i mysql -u'YOUR_MYSQL_USER' -p'YOUR_MYSQL_PASSWORD' -h'YOUR_MYSQL_HOST' -e "{}"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>