Jeroen Moors


Logging mysql queries without touching mysqld
Written on 22 May 2012

While hunting for performance issues, a view on all queries executed by mysql can be very useful.

If you’re on a production system, you probably don’t want to touch the mysqld configuration.

Therefor this little sniplet can be used to sniff the mysql traffic and filter out the useful query stuff.

tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
    if (defined $q) { print "$qn"; }
  } else {
    $_ =~ s/^[ t]+//; $q.=" $_";

If your mysql-connections are not arriving at eth0, you’ll have to change it on the first line near -i eth0 to the right interface.