Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use mysqlsniffer to capture SQL statements

Shulou Source: shulou.com Published: 2022-05-31 21:17:31 09月15日 Update

This article focuses on "how to use mysqlsniffer to capture SQL statements", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to capture SQL statements using mysqlsniffer.

Before MySQL5.1, general log cannot be enabled or disabled at runtime. Sometimes it is troublesome to capture SQL to find problems. Accidentally, I found a very good gadget: mysqlsniffer, which can be used to capture SQL statements. The help is as follows:

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 refers to the network card number, such as eth0,eth2,lo, etc.

Of course, there are also people who directly tcpdump to capture, the method is as follows: [@ more@]

Tcpdump-I eth2-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";}

$qcommodity _

} else {

$_ = ~ s / ^ [t] + / /; $q.= "$_"

}

}'

At this point, I believe you have a deeper understanding of "how to use mysqlsniffer to capture SQL statements". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Sentences content methods learning good practical deeper interest card number practicality practical tools easy to operate more friends websites questions channels trouble help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Tech Info OPPO Reno Linux Xiaomi