tcpdump 抓包sql


tcpdump详解
        http://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html

方式一:用Tcpdump抓取MySQL执行的SQL

参考:http://blog.csdn.net/cnbird2008/article/details/5888741
编写脚本文件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的运行情况。



方式二: 未测试
    tcpdump -i any port 3306 -s 65535 -x -nn -q -tttt -c 100 来收集实时查询,然后用pt-query-digest 生成统计信息

方式三: tcpdump 抓包wireshark分析 
        参考
        http://blog.csdn.net/langeldep/article/details/6156818

        wireshark下载
        http://rj.baidu.com/soft/detail/15788.html?ald


请使用浏览器的分享功能分享到微信等