且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用Tcpdump抓取MySQL执行的SQL

更新时间:2022-09-21 23:16:30

编写脚本文件dumpsql.sh,内容如下:

!/bin/bash
tcpdump -i eth0 -s 0 -l -w out.log port 3306 | strings | perl -e '
#!/bin/bash
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.=" $_" ;
}
}'

运行并抓去sql的执行。

抓取后在当前目录出现out.log文件,执行strings out.log即可看到sql的运行情况。