Created
February 28, 2013 13:13
-
-
Save benoitjpnet/5056619 to your computer and use it in GitHub Desktop.
Kill every MySQL SELECT older than X seconds – Original: https://anothersysadmin.wordpress.com/2008/10/29/kill-every-mysql-select-older-than-x-seconds/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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