Skip to content

Instantly share code, notes, and snippets.

@benoitjpnet
Created February 28, 2013 13:13
Show Gist options
  • Save benoitjpnet/5056619 to your computer and use it in GitHub Desktop.
Save benoitjpnet/5056619 to your computer and use it in GitHub Desktop.
#!/bin/bash
# From https://anothersysadmin.wordpress.com/2008/10/29/kill-every-mysql-select-older-than-x-seconds/
SEC=$1
IFS='|'
if [[ $SEC -lt 1 ]]; then
echo "Usage: $0 SECONDS"
exit 1
fi
mysqladmin proc -v|grep Query|grep -Evi "delete|update|insert|alter table" |while read dummy qid qusr qhost qdb qstat qsec qstat2 query; do
if [ $qsec -gt $SEC ]; then
echo "Killing query $qid..."
mysqladmin kill $qid
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment