Skip to content

Instantly share code, notes, and snippets.

@gengxiankun
Last active January 2, 2019 06:25
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 gengxiankun/2b064445c0db04fece16f71532b863b2 to your computer and use it in GitHub Desktop.
Save gengxiankun/2b064445c0db04fece16f71532b863b2 to your computer and use it in GitHub Desktop.
使用tcpdump抓取sql
#!/bin/bash
#this script used montor mysql network traffic.echo sql
tcpdump -i ${1:eth0} -s 0 -l -w - dst port ${2:3306} | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL)/i)
{
if (defined $q) { print "$q\n"; }
$q=$_;
} else {
$_ =~ s/^[ \t]+//; $q.=" $_";
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment