watch mysql queries as they happen

cunning bit of Perl, not to be used permanently, but very handy indeed for a quick look at what’s actually being queried…

[code]
tcpdump -i eth0 -s 0 -l -w – dst port 3306 | strings | perl -e ‘
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i)
{
if (defined $q) { print "$q\n"; }
$q=$_;
}
else
{
$_ =~ s/^[ \t]+//;
$q.=" $_";
}
}’
[/code]

If your system grumbles that it cannot find tcpdump (command not found), then you either do not have /usr/sbin in your $PATH, or in fact do not have it installed, which is very unlikely!

You could always whack the Perl in a script and then make your one liner shorter:

[code]
tcpdump -i eth0 -s 0 -l -w – dst port 3306 | strings | perl theScript
[/code]




No Comments


No comments yet.



Leave a Reply

Your email address will not be published. Required fields are marked *