Created
April 1, 2020 12:34
-
-
Save hplc/6462dc434f46ef234bbe5e0b8e48358a to your computer and use it in GitHub Desktop.
Kill slow mysql query.
This file contains 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/sh | |
cmd="mysql -uusername -ppassword"; | |
$cmd -e 'show processlist\G' |\ | |
egrep -b5 'Time: [0-9]{2,}' |\ | |
grep 'Id:' |\ | |
cut -d':' -f2 |\ | |
sed 's/^ //' |\ | |
while read id | |
do | |
$cmd -e "kill $id;" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment