Last active
October 4, 2016 17:49
-
-
Save slinkp/25a9e1e97b50b9396c7ea59626f5490e to your computer and use it in GitHub Desktop.
Couple useful shell commands for mysql slow query logs
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
# Find slowest queries | |
grep "^SELECT " mysql-slowquery.log | cut -d ' ' -f 1-5 | sort | uniq -c | sort -n | |
# Now find times for one of those queries. Wrap in single quotes and backslash-escape wildcards | |
QUERY='^SELECT count(\*) FROM `foo` INNER JOIN `blah`' | |
grep -B2 "$QUERY" mysql-slowquery.log | grep Query_time | cut -d ' ' -f 3 | sort -n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment