MySQL Sniffer and mysqlsniffer

Source: Internet
Author: User

MySQL Sniffer and mysqlsniffer

MySQL Sniffer is a 360 open-source MySQL-based packet capture tool that can capture client requests in real time and format output operation statements.
The Operation Review is a good tool for locating problems.

 

Github address: https://github.com/Qihoo360/mysql-sniffer

 

Install

# Yum install glib2-devel libpcap-devel libnet-devel
# Unzip mysql-sniffer-master.zip
# Cd mysql-sniffer-master
# Cmake.

-- Configuring done-- Generating done-- Build files have been written to: /root/mysql-sniffer-master

# Make

Scanning dependencies of target mysql-sniffer[ 16%] Building C object bin/CMakeFiles/mysql-sniffer.dir/main.c.o[ 33%] Building C object bin/CMakeFiles/mysql-sniffer.dir/mysql-dissector.c.o/root/mysql-sniffer-master/src/mysql-dissector.c: In function ‘decode_mysql_lenenc_int’:/root/mysql-sniffer-master/src/mysql-dissector.c:112: warning: dereferencing type-punned pointer will break strict-aliasing rules[ 50%] Building C object bin/CMakeFiles/mysql-sniffer.dir/util.c.o[ 66%] Building CXX object bin/CMakeFiles/mysql-sniffer.dir/session.cpp.o[ 83%] Building CXX object bin/CMakeFiles/mysql-sniffer.dir/sniff-config.cpp.o[100%] Building CXX object bin/CMakeFiles/mysql-sniffer.dir/sniff-log.cpp.oLinking CXX executable mysql-sniffer[100%] Built target mysql-sniffer

# Cd bin/

# Ls

CMakeFiles  cmake_install.cmake  Makefile  mysql-sniffer

 

Parameter description

Parameter descriptions are concise and easy to understand.

# ./mysql-sniffer -helpUsage ./mysql-sniffer [-d] -i eth0 -p 3306,3307,3308 -l /var/log/mysql-sniffer/ -e stderr         [-d] -i eth0 -r 3000-4000         -d daemon mode.         -s how often to split the log file(minute, eg. 1440). if less than 0, split log everyday         -i interface. Default to eth0         -p port, default to 3306. Multiple ports should be splited by ','. eg. 3306,3307            this option has no effect when -f is set.         -r port range, Don't use -r and -p at the same time         -l query log DIRECTORY. Make sure that the directory is accessible. Default to stdout.         -e error log FILENAME or 'stderr'. if set to /dev/null, runtime error will not be recorded         -f filename. use pcap file instead capturing the network interface         -w white list. dont capture the port. Multiple ports should be splited by ','.         -t truncation length. truncate long query if it's longer than specified length. Less than 0 means no truncation         -n keeping tcp stream count, if not set, default is 65536. if active tcp count is larger than the specified count, mysql-sniffer will remove the oldest one

 

Example

#./Mysql-sniffer-I eth0-p 3306

The penultimate column is the number of rows returned.

2017-03-08 11:00:08     root     192.168.244.20     NULL              0ms              1     select @@version_comment limit 12017-03-08 11:00:08     root     192.168.244.20     NULL              0ms              1     select USER()2017-03-08 11:00:10     root     192.168.244.20     NULL              0ms              1     select 12017-03-08 11:01:46     root     192.168.244.20     NULL              0ms              1     SELECT DATABASE()2017-03-08 11:01:46     root     192.168.244.20     test             24ms              0     use test2017-03-08 11:01:46     root     192.168.244.20     test            172ms             14     show databases2017-03-08 11:01:46     root     192.168.244.20     test              0ms             20     show tables2017-03-08 11:01:52     root     192.168.244.20     test              0ms             20     show tables2017-03-08 11:01:57     root     192.168.244.20     test             58ms              9     select * from test12017-03-08 11:02:17     root     192.168.244.20     test              0ms              1     SELECT DATABASE()2017-03-08 11:02:17     root     192.168.244.20     test              0ms              0     use test

 

Note:

1. Only the newly created link can be crawled. If it is a previously created link, the user name and database name cannot be obtained, and there is a probability of packet loss.

2. If the client is local and the tcp connection is used, for example, mysql-h 192.168.244.10-uroot-p123456, where 192.168.244.10 is the ip address of the local host,
It can only be captured through the loop address,./mysql-sniffer-I lo-p 3306

 

Reference

Https://github.com/Qihoo360/mysql-sniffer/blob/master/README_CN.md

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.