Skip to content

Instantly share code, notes, and snippets.

@hplc
Created April 1, 2020 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hplc/6462dc434f46ef234bbe5e0b8e48358a to your computer and use it in GitHub Desktop.
Save hplc/6462dc434f46ef234bbe5e0b8e48358a to your computer and use it in GitHub Desktop.
Kill slow mysql query.
#!/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