嘻嘻哈哈的部落格(blog) ? 用tcpdump抓mysql的查询语句

来源:百度文库 编辑:神马文学网 时间:2024/04/28 13:42:33

用tcpdump抓mysql的查询语句

2008年1月21日 哈哈 发表评论 阅读评论

在mysql的官方网站上找到几个用tcpdump来抓在mysql server上跑的sql语句
# — (1.1) To capture all traffic on the interface eth0, run:
time tcpdump -i eth0 -s 1500 -w 20060427-db-traffic-01.dmp

# — (1.2) To capture traffic on the interface eth0 coming from a specific IP address, run:
time tcpdump -i eth0 -s 1500 src host 192.168.2.10 -w 20060427-db-traffic-01.dmp

# — Press Ctrl+C — do not leave tcpdump running infinitely on high traffic interfaces

# — (2) To process the results, run:
strings 20060427-db-traffic-01.dmp | grep -i ’select’ | awk ‘{printf(”%s %s %s %s\n”, $1,$2,$3, $4);}’| sort| uniq -c | awk ‘{printf(”%06ld %s %s %s %s\n”, $1,$2,$3,$4,$5);}’|sort

还有一句诗:
tcpdump -l -i eth0 -w - src or dst port 3306 | strings