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 ar mysqlsniffer par 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? Jums ražošanas datu bāzes servera, un to nevar ļaut query meža ..., tad kā Jūs redzat queries tiek izpildīts pret datu bāzi?

The answer: use a modified network sniffer to parse out the MySQL packets and decode them. Atbilde: izmantot modificētu tīkla sniffer parsēt no MySQL pakešu un atkodēt tos. You'll have to do a little compiling, but it'll be worth it. Jums ir jādara nedaudz apkopojot, bet tas būs tā vērts. Note that this will not usually work for local connections, although you are welcome to try. Ņemiet vērā, ka tas parasti strādā vietējo savienojumus, kaut arī esat laipni aicināti izmēģināt.

First, you need to install libpcap-dev, which is the development library that allows an application to sniff network packets. Pirmkārt, jums ir nepieciešams instalēt libpcap-dev, kas ir attīstības bibliotēka, kas ļauj piemērot šņaukāties tīkla paketes.

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 Now let's make direktorijā, lejupielādēt pirmkodu un sastādīt to

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. Šajā brīdī mums ir spīdīga jaunu izpildāmais nosaukts mysqlsniffer mūsu avota direktorijā. You can copy it wherever you like (somewhere in the path would be useful) Jūs varat kopēt to, kur vien vēlaties (kaut kur virzība būtu ērti)

To run mysqlsniffer, you need to specify the network interface that MySQL is listening on. Lai palaistu mysqlsniffer, jums jānorāda tīkla saskarnes, ka MySQL ir klausās. For me, it's eth0. Man, tas eth0.

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

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. Slodzes sīkumi sāk lidojot ... let's filter it out nedaudz vairāk, lai mēs varētu tikai iegūt jautājumus un ne visu lieko informāciju.

$ sudo /path/to/mysqlsniffer –no-mysql-hdrs eth0 | grep COM_QUERY $ Sudo / path / uz / 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 NOSAUKUMU 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 COLUMNS FROM `db2842_howto`. "Wp_users`

Ah, now there we are… all sorts of query information, without having to restart MySQL. Ah, tagad mēs ... visi pieprasījumi veida informācijai, neuzsākot MySQL.

Here are the full options for the command: Šeit ir pilnīgi iespējas komandu:

Usage: mysqlsniffer [OPTIONS] INTERFACE Usage: mysqlsniffer [opcijas] INTERFACE

OPTIONS: Opcijas:
–port N Listen for MySQL on port number N (default 3306) -Port N Klausies par MySQL uz porta numuru N (default 3.306)
–verbose Show extra packet information -Runīgs Rādīt papildu pakešu informācija
–tcp-ctrl Show TCP control packets (SYN, FIN, RST, ACK) -TCP-ctrl Show TCP kontroles paketēm (SYN, FIN, RST, ACK)
–net-hdrs Show major IP and TCP header values -Net-hdrs Show lielu IP un TCP header vērtībām
–no-mysql-hdrs Do not show MySQL header (packet ID and length) -No-mysql-hdrs Nerādīt MySQL header (pakešu ID un ilgums)
–state Show state -State Show valsts
–v40 MySQL server is version 4.0 -V40 MySQL serveris ir versija 4.0
–dump Dump all packets in hex -Dump dump visu pakešu hex
–help Print this -Help Izdrukāt šo

Original source code and more information at: Sākotnējo pirmkodu, un vairāk informācijas:
http://hackmysql.com/mysqlsniffer http://hackmysql.com/mysqlsniffer

If you are running on a development server, it would be easier to just Ja jūs strādājat ar attīstības serverī, tas būtu vieglāk vienkārši turn on query logging ieslēgt query mežizstrāde . .

This article was originally written on 05/25/07 Tagged with: Šis pants tika sākotnēji rakstīts uz 05/25/07 tagged with: Ubuntu Ubuntu

Daily Email Updates Daily Email Updates

You can get our how-to articles in your inbox each day for free. Jūs varat saņemt mūsu how-to rakstus savā pastkastītē katru dienu par brīvu. Just enter your name and email below: Vienkārši ievadiet jūsu vārdu un e-pasta zemāk:


Name: Vārds:
Email: E-pasts:

Our Friends Our Friends
Getting Started Getting Started


About How-To Geek Par How-To Geek
What Is That Process? Kas ir šis process?
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.