MySQL admin emergency processlist kill script

81

Ever been caught off guard by a user running a daft query against the database thats causing everything to stack up??

This script is a quick and dirty way to get rid of everything that active ‘now’, and has been used on occasions where users have run a query that locks a table thats required elsewhere, but they havent checked the impact of their changes. Its not a good way to run things, but can help temporarily sort service issues, particularly when no one will admit that they are the person thats run a dodgy query ;-)

#/bin/sh

AWK=/usr/awk

ADMIN_PATH=/usr/local/bin

$ADMIN_PATH/mysqladmin processlist -h127.0.0.1 -p<password>|$AWK ‘{ print $2}’ > processes.txt
for i in `cat processes.txt`; do $ADMIN_PATH/mysqladmin -h127.0.0.1 -p<password> kill $i; echo “killed $i”; done