Created
October 9, 2018 19:33
-
-
Save DavidGoodwin/52e9f93725d5c6181f23300226f4e6bb to your computer and use it in GitHub Desktop.
Kill long running MySQL queries (in AWS RDS)
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/bash | |
MYSQL="mysql --defaults-extra-file=/path/to/something.cnf" | |
# Find queries which have been running for longer than 1800 seconds. | |
for PID in $($MYSQL -BNe "SELECT id FROM information_schema.processlist WHERE command <> 'Sleep' AND info NOT LIKE '%PROCESSLIST%' AND command <> 'Killed' AND time > 1800" ) | |
do | |
#OUTPUT=$($MYSQL -NBe "SELECT id,time,command,info FROM information_schema.processlist WHERE id = $PID ") | |
#echo "Long running query output - $OUTPUT " | |
# In AWS RDS : | |
$MYSQL -e "call mysql.rds_kill($PID)" | |
# For normal MySQL : | |
# $MYSQL -e "kill $PID" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!