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.
MySQL network protocol traffic from the command "mysqladmin -u root -h 127.0.0.1 processlist":
mysqlsniffer listening for MySQL on interface lo port 3306
server > 127.0.0.1.3051: ID 0 len 70 Handshake (Caps: Get all column flags, Connect w/DB, Compression, )
127.0.0.1.3051 > server: ID 1 len 38 Handshake (new auth) <user root db (null) max pkt 1073741824> (Caps: Long password, Get all column flags, LOAD DATA LOCAL, 4.1 protocol, Transactions, 4.1 authentication, )
server > 127.0.0.1.3051: ID 2 len 7 OK (Status: Auto-commit, )
127.0.0.1.3051 > server: ID 0 len 17 COM_QUERY: show processlist
server > 127.0.0.1.3051: ID 1 len 1 8 Fields
ID 2 len 24 Field: ..Id
ID 3 len 26 Field: ..User
ID 4 len 26 Field: ..Host
ID 5 len 24 Field: ..db
ID 6 len 29 Field: ..Command
ID 7 len 26 Field: ..Time
ID 8 len 27 Field: ..State
ID 9 len 26 Field: ..Info
ID 10 len 5 End (Status: Auto-commit, )
ID 11 len 49 || 1 | root | localhost:3051 | NULL | Query | 0 | NULL | show processlist ||
ID 12 len 5 End (Status: Auto-commit, )
127.0.0.1.3051 > server: ID 0 len 1 COM_QUIT
mysqlsniffer exited cleanly.
17 MySQL packets captured (469 bytes)