Created
January 15, 2020 12:09
-
-
Save tluyben/7ab77fb0749764deddd2e7327362b8fb to your computer and use it in GitHub Desktop.
explain all mysql queries in log
This file contains hidden or 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
#!/usr/bin/perl | |
# enable query log for mysql | |
open(F, "tail -f ~/query.log|"); | |
while(<F>){ | |
chomp; | |
if (/\d+\s+Execute\s+(select.*)$/igsm) { | |
print "\n\nQuery: $1 : \n"; | |
$qry = $1; | |
$qry =~ s/\`/\\\`/isgm; | |
print `mysql -u root --password=root forge -e "explain $qry"`; | |
} | |
} | |
close F; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment