mysql案例~tcpdump的使用
使用方式 tcpdump -i eth0 -s 0 -l -w - dst port 3306
参数说明
-i 设备名称
-s 包大小,默认65535
-l 输出缓冲
-w 输入文件中
dst port 监听目标端口
记录执行sql
#!/bin/bash
#this script used montor mysql network traffic.echo sql
tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL)/i)
{
if (defined $q) { print "$q\n"; }
$q=$_;
} else {
$_ =~ s/^[ \t]+//; $q.=" $_";
}
}' >> /tmp/tmp.log
根据关键字分析tmp日志