Skip to content

Instantly share code, notes, and snippets.

@slinkp
Last active October 4, 2016 17:49
Show Gist options
  • Save slinkp/25a9e1e97b50b9396c7ea59626f5490e to your computer and use it in GitHub Desktop.
Save slinkp/25a9e1e97b50b9396c7ea59626f5490e to your computer and use it in GitHub Desktop.
Couple useful shell commands for mysql slow query logs
# 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