Skip to content

Instantly share code, notes, and snippets.

@callumj
Last active December 25, 2015 08:19
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 callumj/6946282 to your computer and use it in GitHub Desktop.
Save callumj/6946282 to your computer and use it in GitHub Desktop.
tcpdump for MySQL - recording table modifications.
tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(INSERT|UPDATE)/) {
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$time = "$hour:$min";
if (defined $q) {
if ($q =~ /INSERT\s+INTO\s+`(\w+)`/) {
print "$time,insert,$1\n";
}
if ($q =~ /UPDATE\s+`(\w+)`/) {
print "$time,update,$1\n";
}
}
$q=$_;
} else {
$_ =~ s/^[ \t]+//; $q.=" $_";
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment