-
-
Save andresaquino/e0d9c1803944d7600a92e2c4a7d00f00 to your computer and use it in GitHub Desktop.
Finding long-running queries in MySQL
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
SELECT id,state,command,time,left(replace(info,'\n','<lf>'),120) | |
FROM information_schema.processlist | |
WHERE command <> 'Sleep' | |
AND info NOT LIKE '%PROCESSLIST%' | |
ORDER BY time DESC LIMIT 50; |
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
host="octopus-read-1" | |
password=XXXXXXX | |
client="mysql -uhousetrip -p${password} --ssl-ca=/var/www/housetrip/shared/config/mysql-ssl-ca-cert.pem -h ${host}.cjumddpb9pgp.eu-west-1.rds.amazonaws.com housetrip_production" | |
query="SELECT id | |
FROM information_schema.processlist | |
WHERE command <> 'Sleep' | |
AND info NOT LIKE '%PROCESSLIST%' | |
AND command <> 'Killed' | |
AND info LIKE '%EXPLAIN'" | |
$client -e "${query}" | \ | |
sed -e 's/[^0-9]//g; s/^/kill /; s/$/;/' | { | |
while read LINE ; do | |
echo "$LINE" | |
echo "$LINE" | $client | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment