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 dotazov sa mysqlsniffer na 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? You've got a produkčné databázový server, a vy nemôžete povoliť zapisovanie dotaz ... tak, ako vidíte dotazov sa vykonáva proti databázu?

The answer: use a modified network sniffer to parse out the MySQL packets and decode them. Odpoveď: Použite upravené sieť stopovacími k analýze z MySQL pakety a dekódovať ich. You'll have to do a little compiling, but it'll be worth it. Budete musieť urobiť trochu kompilácie, ale bude to stáť za to. Note that this will not usually work for local connections, although you are welcome to try. Všimnite si, že to nebude zvyčajne pracujú pre miestne spoje, aj keď ste vítaní vyskúšať.

First, you need to install libpcap-dev, which is the development library that allows an application to sniff network packets. Po prvé, je potrebné nainštalovať libpcap-dev, čo je knižnica, ktorá umožňuje vývoj aplikácií pre čuchať sieťových paketov.

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 Teraz sa poďme urobiť adresár, stiahnite si zdrojový kód a skompilovať

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. V túto chvíľu máme zbrusu nový spustiteľný súbor mysqlsniffer v našom zdrojovom adresári. You can copy it wherever you like (somewhere in the path would be useful) Môžete skopírovať kam chcete (niekde na ceste by bolo užitočné)

To run mysqlsniffer, you need to specify the network interface that MySQL is listening on. Ak chcete spustiť mysqlsniffer, musíte zadať sieťové rozhranie, ktoré MySQL je na počúvanie. For me, it's eth0. Pre mňa je to eth0.

sudo /path/to/mysqlsniffer eth0 sudo / cesta / k / 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. Veľa vecí začína rokmi ... poďme filter to trochu viac, takže môžeme len získať dotazov a nie všetky prebytočné informácie.

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

192.168.73.1.2622 > server: COM_QUERY: SELECT @@sql_mode 192.168.73.1.2622> server: COM_QUERY: SELECT @ @ sql_mode
192.168.73.1.2622 > server: COM_QUERY: SET SESSION sql_mode=” 192.168.73.1.2622> server: COM_QUERY: SET SESSION sql_mode = "
192.168.73.1.2622 > server: COM_QUERY: SET NAMES utf8 192.168.73.1.2622> server: COM_QUERY: SET NAMES utf8
192.168.73.1.1636 > server: COM_QUERY: SELECT @@SQL_MODE 192.168.73.1.1636> server: 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> server: COM_QUERY: SHOW FULL stĺpcov db2842_howto ``. "Wp_users"

Ah, now there we are… all sorts of query information, without having to restart MySQL. Aha, už tam sme ... všetky druhy dotazu informácií, aby bolo potrebné reštartovať MySQL.

Here are the full options for the command: Tu sú plné možnosti príkazu:

Usage: mysqlsniffer [OPTIONS] INTERFACE Použitie: mysqlsniffer [OPTIONS] INTERFACE

OPTIONS: MOŽNOSTI:
–port N Listen for MySQL on port number N (default 3306) N-port Počúvajte MySQL na porte číslo N (predvolené 3306)
–verbose Show extra packet information -Verbose Zobraziť ďalšie informácie o paketu
–tcp-ctrl Show TCP control packets (SYN, FIN, RST, ACK) -Tcp-ctrl Zobraziť TCP kontroly paketov (SYN, FIN, RST, ACK)
–net-hdrs Show major IP and TCP header values -Net-hdrs Zobraziť hlavné IP a TCP hlavičky hodnoty
–no-mysql-hdrs Do not show MySQL header (packet ID and length) -No-mysql-hdrs nezobrazovať MySQL header (packet ID a dĺžka)
–state Show state -State Zobraziť stav
–v40 MySQL server is version 4.0 -V40 MySQL server verzie 4.0
–dump Dump all packets in hex -Dump výpis všetkých paketov v hex
–help Print this -Help Print this

Original source code and more information at: Pôvodný zdrojový kód a ďalšie informácie na adrese:
http://hackmysql.com/mysqlsniffer http://hackmysql.com/mysqlsniffer

If you are running on a development server, it would be easier to just Ak ste beží na rozvoj serveri, bolo by jednoduchšie turn on query logging Zapnutie protokolovanie dotazu . .

This article was originally written on 05/25/07 Tagged with: Tento článok bol pôvodne napísaný na 05/25/07 Tagged s: Ubuntu Ubuntu

Daily Email Updates Denný Svářeč

You can get our how-to articles in your inbox each day for free. Môžete si naše jak-na články vo vašej schránky každý deň zadarmo. Just enter your name and email below: Stačí zadať svoje meno a e-mail nižšie:


Name: Meno:
Email: E-mail:

Leave a Comment Zanechať komentár




Leave your Zanechajte svoj friendly priateľský comment here. komentár tu.

If you have a computer help question, Ak máte počítač pomôže otázku, click here to leave it on the forums kliknite tu nechať to na fórach instead. miesto.

Note: Your comment may not show up immediately on the site. Poznámka: Váš komentár sa nezobrazia okamžite na mieste.

Our Friends Naši priatelia
Getting Started Začíname


About How-To Geek O tom, ako-To Geek
What Is That Process? Čo je to za proces?
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. Copyright © 2006-2009 HowToGeek.com. All Rights Reserved. All Rights Reserved.