Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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