Important! This is an automatic machine translated page. If you can read english, you should Click Here to read the original English version of the article.

Track MySQL Queries with mysqlsniffer on Ubuntu Track MySQL Queries với mysqlsniffer trên Ubuntu

You've got a production database server, and you can't enable query logging… so how do you see the queries being executed against the database? Bạn đã có một máy chủ cơ sở dữ liệu sản xuất, và bạn không thể kích hoạt tính năng truy vấn khai thác gỗ ... nên làm thế nào để bạn nhìn thấy các truy vấn được thực hiện đối với cơ sở dữ liệu?

The answer: use a modified network sniffer to parse out the MySQL packets and decode them. Câu trả lời: sử dụng một mạng lưới đổi sniffer phân tích ra các gói dữ liệu MySQL và giải mã chúng. You'll have to do a little compiling, but it'll be worth it. Bạn sẽ phải làm biên dịch một chút, nhưng nó sẽ có giá trị nó. Note that this will not usually work for local connections, although you are welcome to try. Lưu ý rằng điều này thường sẽ không làm việc cho các kết nối địa phương, mặc dù bạn có cố gắng.

First, you need to install libpcap-dev, which is the development library that allows an application to sniff network packets. Trước tiên, bạn cần phải cài đặt libpcap-dev, mà là các thư viện phát triển, cho phép một ứng dụng để sniff gói mạng.

sudo apt-get install libpcap-dev sudo apt-get install libpcap-dev

Now let's make a directory, download the source code and compile it Bây giờ hãy tạo một thư mục, tải về mã nguồn và biên dịch nó

mkdir mysqlsniffer mkdir mysqlsniffer

cd mysqlsniffer cd mysqlsniffer

wget hackmysql.com/code/mysqlsniffer.tgz wget hackmysql.com / code / mysqlsniffer.tgz

tar xvfz mysqlsniffer.tgz tar xvfz mysqlsniffer.tgz

gcc -O2 -lpcap -o mysqlsniffer mysqlsniffer.c packet_handlers.c misc.c gcc-O2-lpcap-o mysqlsniffer mysqlsniffer.c packet_handlers.c misc.c

At this point, we have a shiny new executable named mysqlsniffer in our source directory. You can copy it wherever you like (somewhere in the path would be useful) Bạn có thể sao chép nó bất cứ nơi nào bạn thích (một nơi nào đó trong đường dẫn sẽ là hữu ích)

To run mysqlsniffer, you need to specify the network interface that MySQL is listening on. Để chạy mysqlsniffer, bạn cần phải chỉ định giao diện mạng mà MySQL đang lắng nghe trên. For me, it's eth0. Đối với tôi, đó là eth0.

sudo /path/to/mysqlsniffer eth0 sudo / path / to / mysqlsniffer eth0

Loads of stuff starts flying by… let's filter it out a little more so we can just get the queries and not all the excess data. Loads of stuff bắt đầu bay bằng cách ... hãy lọc nó ra nhiều hơn một chút vì vậy chúng tôi chỉ có thể nhận được các truy vấn và không phải tất cả các dữ liệu dư thừa.

$ sudo /path/to/mysqlsniffer –no-mysql-hdrs eth0 | grep COM_QUERY $ Sudo / path / to / mysqlsniffer-no-mysql-hdrs eth0 | grep COM_QUERY

192.168.73.1.2622 > server: COM_QUERY: SELECT @@sql_mode 192.168.73.1.2622> máy chủ: COM_QUERY: SELECT @ @ sql_mode
192.168.73.1.2622 > server: COM_QUERY: SET SESSION sql_mode=” 192.168.73.1.2622> máy chủ: COM_QUERY: SET SESSION sql_mode = "
192.168.73.1.2622 > server: COM_QUERY: SET NAMES utf8 192.168.73.1.2622> máy chủ: COM_QUERY: SET NAMES utf8
192.168.73.1.1636 > server: COM_QUERY: SELECT @@SQL_MODE 192.168.73.1.1636> máy chủ: COM_QUERY: SELECT @ @ SQL_MODE
192.168.73.1.1636 > server: COM_QUERY: SHOW FULL COLUMNS FROM `db2842_howto`.`wp_users` 192.168.73.1.1636> máy chủ: COM_QUERY: Full SHOW COLUMNS FROM `db2842_howto` `wp_users.`

Ah, now there we are… all sorts of query information, without having to restart MySQL. Ah, bây giờ có chúng tôi là ... tất cả các loại truy vấn thông tin, mà không cần phải khởi động lại MySQL.

Here are the full options for the command: Dưới đây là những tùy chọn đầy đủ cho các lệnh:

Usage: mysqlsniffer [OPTIONS] INTERFACE Cách sử dụng: mysqlsniffer [OPTIONS] Interface

OPTIONS: OPTIONS:
–port N Listen for MySQL on port number N (default 3306) -Port N Nghe cho MySQL trên N số cổng (mặc định 3306)
–verbose Show extra packet information -Verbose hiển thị thông tin gói thêm
–tcp-ctrl Show TCP control packets (SYN, FIN, RST, ACK) -Tcp-ctrl Show kiểm soát các gói tin TCP (SYN, FIN, RST, ACK)
–net-hdrs Show major IP and TCP header values -Net-hdrs Show lớn IP và các giá trị tiêu đề TCP
–no-mysql-hdrs Do not show MySQL header (packet ID and length) -No-mysql-hdrs Không hiển thị tiêu đề MySQL (gói ID và chiều dài)
–state Show state -Bang Show nhà nước
–v40 MySQL server is version 4.0 -V40 là máy chủ MySQL phiên bản 4.0
–dump Dump all packets in hex -Dump dump tất cả các gói dữ liệu ở dạng thập lục
–help Print this -Giúp In

Original source code and more information at: Mã nguồn gốc và biết thêm thông tin tại:
http://hackmysql.com/mysqlsniffer http://hackmysql.com/mysqlsniffer

If you are running on a development server, it would be easier to just Nếu bạn đang chạy trên một máy chủ phát triển, nó sẽ dễ dàng hơn để chỉ turn on query logging bật truy vấn đăng nhập . .

This article was originally written on 05/25/07 Tagged with: Bài viết này ban đầu được viết ngày 05/25/07 Tagged với: Ubuntu Ubuntu

Daily Email Updates Email cập nhật hàng ngày

You can get our how-to articles in your inbox each day for free. Bạn có thể làm thế nào chúng tôi vào các bài viết trong hộp thư của bạn mỗi ngày miễn phí. Just enter your name and email below: Chỉ cần nhập tên và email của bạn dưới đây:


Name: Tên:
Email: Email:

Our Friends Bạn bè của chúng tôi
Getting Started Bắt đầu


About How-To Geek Giới How-To Geek
What Is That Process? Quá trình đó là gì?
svchost.exe svchost.exe
jusched.exe jusched.exe
dwm.exe dwm.exe
ctfmon.exe ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
wmpnscfg.exe wmpnscfg.exe
rundll32.exe rundll32.exe
wfcrun32.exe wfcrun32.exe
Ipoint.exe Ipoint.exe
Itype.exe Itype.exe
Wfica32.exe Wfica32.exe
Mobsync.exe Mobsync.exe
conhost.exe conhost.exe
Dpupdchk.exe Dpupdchk.exe Adobe_Updater.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. Bản quyền © 2006-2009 HowToGeek.com. All Rights Reserved. Tất cả các quyền.