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 consultes amb mysqlsniffer en 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? Vostè té un servidor de base de dades de producció, i no es pot permetre el registre de consultes ... així que com veu vostè les consultes que s'executaran a la base de dades?

The answer: use a modified network sniffer to parse out the MySQL packets and decode them. La resposta: fer servir un sniffer de xarxa vegada per analitzar els paquets de MySQL i desxifrat. You'll have to do a little compiling, but it'll be worth it. Vostè haurà de fer una mica de compilar, però valdrà la pena. Note that this will not usually work for local connections, although you are welcome to try. Tingueu en compte que això no sol treballar per connexions locals, tot i que us convidem a provar.

First, you need to install libpcap-dev, which is the development library that allows an application to sniff network packets. En primer lloc, cal instal lar libpcap-dev, que és la biblioteca de desenvolupament que permet que una aplicació Sniff de paquets de xarxa.

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 Ara anem a crear un directori, descarregar el codi font i compilar -

mkdir mysqlsniffer mysqlsniffer mkdir

cd mysqlsniffer mysqlsniffer cd

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

tar xvfz mysqlsniffer.tgz mysqlsniffer.tgz tar xvfz

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. En aquest punt, tenim un nou i brillant mysqlsniffer executable anomenat en el nostre directori d'origen. You can copy it wherever you like (somewhere in the path would be useful) Podeu copiar on vulguis (en algun lloc del camí seria útil)

To run mysqlsniffer, you need to specify the network interface that MySQL is listening on. Per executar mysqlsniffer, cal especificar la interfície de xarxa que MySQL està escoltant. For me, it's eth0. Per a mi, és 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. Piles de coses comença a volar per ... anem a filtrar cap a fora una mica més pel que només pot obtenir les consultes i no totes les dades en excés.

$ sudo /path/to/mysqlsniffer –no-mysql-hdrs eth0 | grep COM_QUERY Ruta $ sudo / / a / mysqlsniffer-no-mysql-IDH eth0 | grep COM_QUERY

192.168.73.1.2622 > server: COM_QUERY: SELECT @@sql_mode 192.168.73.1.2622> Servidor: COM_QUERY: SELECT @ @ sql_mode
192.168.73.1.2622 > server: COM_QUERY: SET SESSION sql_mode=” 192.168.73.1.2622> Servidor: COM_QUERY: sql_mode en la seva sessió SET = "
192.168.73.1.2622 > server: COM_QUERY: SET NAMES utf8 192.168.73.1.2622> Servidor: COM_QUERY: SET NAMES utf8
192.168.73.1.1636 > server: COM_QUERY: SELECT @@SQL_MODE 192.168.73.1.1636> Servidor: 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> Servidor: COM_QUERY: SHOW FULL COLUMNS FROM `db2842_howto». Wp_users ``

Ah, now there we are… all sorts of query information, without having to restart MySQL. Ah, ara estem ... tot tipus d'informació de consulta, sense haver de reiniciar MySQL.

Here are the full options for the command: Aquí hi ha les opcions complerta de la comanda:

Usage: mysqlsniffer [OPTIONS] INTERFACE Ús: mysqlsniffer [OPCIONS] INTERFACE

OPTIONS: OPCIONS:
–port N Listen for MySQL on port number N (default 3306) Port N Escolti per MySQL en el nombre de port N (per defecte 3306)
–verbose Show extra packet information -Verbose Mostra informació del paquet extra
–tcp-ctrl Show TCP control packets (SYN, FIN, RST, ACK) -TCP-ctrl Mostra els paquets de control de TCP (SYN, FIN, RST, ACK)
–net-hdrs Show major IP and TCP header values -Net-IDH Show IP principals i els valors de capçalera TCP
–no-mysql-hdrs Do not show MySQL header (packet ID and length) -No-mysql-IDH No mostrar el encapçalat MySQL (ID de paquets i longitud)
–state Show state -Mostra l'estat de l'estat
–v40 MySQL server is version 4.0 V40-servidor de MySQL és la versió 4.0
–dump Dump all packets in hex -Dump bolcat de tots els paquets en hexadecimal
–help Print this Imprimeix aquesta ajuda

Original source code and more information at: El codi font original i més informació a:
http://hackmysql.com/mysqlsniffer http://hackmysql.com/mysqlsniffer

If you are running on a development server, it would be easier to just Si esteu executant en un servidor de desenvolupament, seria més fàcil simplement turn on query logging al seu torn en el registre de consultes . .

This article was originally written on 05/25/07 Tagged with: Aquest article va ser originalment escrit en 05/25/07 Tagged amb: Ubuntu Ubuntu

Daily Email Updates Daily Email Updates

You can get our how-to articles in your inbox each day for free. Vostè pot obtenir el nostre com-als articles a la teva safata d'entrada cada dia de forma gratuïta. Just enter your name and email below: Només cal que introdueixis el teu nom i correu electrònic a continuació:


Name: Nom:
Email: Email:

Our Friends Els nostres Amics
Getting Started Com començar


About How-To Geek Sobre How-To Geek
What Is That Process? Què és aquest procés?
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 Jusched.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. Copyright © 2006-2009 HowToGeek.com. All Rights Reserved. Tots els drets reservats.