使用mysqlsniffer捕获SQL语句_MySQL
bitsCN.com
MySQL5.1之前general log不能在运行时启用或禁用,有时想捕捉SQL来查找问题就很麻烦,偶然间发现一个很不错的小工具:mysqlsniffer,可以用来捕捉SQL语句,使用帮助如下:
mysqlsniffer --help
mysqlsniffer v1.2 - Watch MySQL traffic on a TCP/IP network
Usage: mysqlsniffer [OPTIONS] INTERFACE
OPTIONS:
--port N Listen for MySQL on port number N (default 3306)
--verbose Show extra packet information
--tcp-ctrl Show TCP control packets (SYN, FIN, RST, ACK)
--net-hdrs Show major IP and TCP header values
--no-mysql-hdrs Do not show MySQL header (packet ID and length)
--state Show state
--v40 MySQL server is version 4.0
--dump Dump all packets in hex
--help Print this
Original source code and more information at:
http://hackmysql.com/mysqlsniffer
INTERFACE是指网卡号,如eth0,eth1,lo等。
当然也有人直接tcpdump来捕捉的,方法如下:
tcpdump -i eth1 -s 0 -l -w - dst port 3306 | strings | perl -e
while() { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i) {
if (defined $q) { print "$qn"; }
$q=$_;
} else {
$_ =~ s/^[ t]+//; $q.=" $_";
}
}
mysqlsniffer is a tcpdump clone specifically for dumping/sniffing/watching MySQL network protocol traffic over TCP/IP networks. mysqlsniffer is coded in C using the pcap library and works with MySQL version 4.0 and newer. mysqlsniffer is the only MySQL-specific network sniffer.
mk-query-digest also understands the MySQL protocol. It’s not a sniffer, though. It reads packet dumps from tcpdump like a slowlog. If you want to analyze queries from the wire (i.e. from network traffic), mk-query-digest is what you want.
For more information about the MySQL protocol read MySQL Internals ClientServer Protocol.
http://hackmysql.com/mysqlsniffer
1、下载软件包 http://hackmysql.com/code/mysqlsniffer.tgz
2、编译安装 root@real1 mysqlsniffer]# gcc -O2 -lpcap -o mysqlsniffer mysqlsniffer.c packet_handlers.c misc.c
如果出现如下提示
请安装libpcap-devel 包,再重新用gcc来编译
mysqlsniffer.c:26:18: 错误:pcap.h:没有那个文件或目录
[root@real1 mysqlsniffer]# ./mysqlsniffer

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

Go语言中哪些库是大公司开发或知名开源项目?在使用Go语言进行编程时,开发者常常会遇到一些常见的需求,�...

在Avue组件库中实现Avue-crud行编辑的onBlur事件手动触发Avue-crud组件提供了便捷的行内编辑功能,但有时我们需要�...

如何在后端开发中快速搭建前台页面?作为一个拥有三四年经验的后端开发者,掌握了基础的javascript、css和html�...

GiteePages静态网站部署失败:404错误排查与解决在使用Gitee...

在ChromeDevTools中如何有效修改并重放请求的Cookies在使用Chrome...

Go框架的受众现状分析在当前的Go编程生态中,开发者们常常面临选择合适的框架来满足其业务需求。今天我们�...

网页自动化与数值计算:基于浏览器内嵌脚本的实现本文将探讨如何使用浏览器内嵌脚本实现网页元素操作和数...
