Skip to content

Instantly share code, notes, and snippets.

@tluyben
Created January 15, 2020 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tluyben/7ab77fb0749764deddd2e7327362b8fb to your computer and use it in GitHub Desktop.
Save tluyben/7ab77fb0749764deddd2e7327362b8fb to your computer and use it in GitHub Desktop.
explain all mysql queries in log
#!/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