日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql抓包_mysql抓包工具

發(fā)布時間:2023/12/3 数据库 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql抓包_mysql抓包工具 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

簡介

MySQL Sniffer 是一個基于 MySQL 協(xié)議的抓包工具,實時抓取 MySQLServer 端或 Client 端請求,并格式化輸出。輸出內容包括訪問時間、訪問用戶、來源 IP、訪問 Database、命令耗時、返回數(shù)據(jù)行數(shù)、執(zhí)行語句等。有批量抓取多個端口,后臺運行,日志分割等多種使用方式,操作便捷,輸出友好。

同時也適用抓取 Atlas 端的請求,Atlas 是奇虎開源的一款基于MySQL協(xié)議的數(shù)據(jù)中間層項目,項目地址:https://github.com/Qihoo360/Atlas

同類型工具還有vc-mysql-sniffer,以及 tshark 的 -e mysql.query 參數(shù)來解析 MySQL 協(xié)議。

使用

建議在 centos6.2 及以上編譯安裝,并用 root 運行。

依賴

glib2-devel、libpcap-devel、libnet-devel

安裝

git clone git@github.com:Qihoo360/mysql-sniffer.git

cd mysql-sniffer

mkdir proj

cd proj

cmake ../

make

cd bin/

參數(shù):

./mysql-sniffer -h

Usage 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

示例

1. 實時抓取某端口信息并打印到屏幕

輸出格式為:時間,訪問用戶,來源 IP,訪問 Database,命令耗時,返回數(shù)據(jù)行數(shù),執(zhí)行語句。

mysql-sniffer -i eth0 -p 3306

2017-02-23 14:47:45???? testuser???? 10.xx.xx.xx???? NULL??????????????0ms??????????????1???? select @@version_comment limit 1

2017-02-23 14:47:45???? testuser???? 10.xx.xx.xx???? NULL??????????????0ms??????????????1???? select USER()

2017-02-23 14:47:48???? testuser???? 10.xx.xx.xx???? NULL??????????????0ms???????????? 13???? show databases

2017-02-23 14:47:51???? testuser???? 10.xx.xx.xx???? NULL??????????????0ms??????????????1???? SELECT DATABASE()

2017-02-23 14:47:51???? testuser???? 10.xx.xx.xx???? mysql??????????????0ms??????????????0???? use mysql

2017-02-23 14:47:53???? testuser???? 10.xx.xx.xx???? mysql??????????????0ms???????????? 29???? show tables

2017-02-23 14:47:54???? testuser???? 10.xx.xx.xx???? mysql??????????????0ms??????????????1???? select 1

2017-02-23 14:48:01???? testuser1???? 10.xx.xx.xx???? NULL??????????????0ms??????????????0???? set autocommit=1

2017-02-23 14:48:01???? testuser1???? 10.xx.xx.xx???? NULL??????????????0ms??????????????0???? set autocommit=1

2. 實時抓取某端口信息并打印到文件

-l 指定日志輸出路徑,日志文件將以 port.log 命名。

mysql-sniffer -i eth0 -p 3306 -l /tmp

3. 實時抓取多個端口信息并打印到文件

-l 指定日志輸出路徑,-p 指定需要抓取的端口列表逗號分割。日志文件將以各自 port.log 命名。

mysql-sniffer -i eth0 -p 3306,3307,3310 -l /tmp

……

問題

有l(wèi)vs環(huán)境下,如果client IP是保存在在每個連接階段的tcp opt字段中,那么mysql-sniffer提取的真實的client IP而不是lvs的IP。

只能抓取新建的鏈接,如果是之前創(chuàng)建的鏈接將獲取不到用戶名和庫名,并有一定幾率丟包。

總結

以上是生活随笔為你收集整理的mysql抓包_mysql抓包工具的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。