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.

Monitor All SQL Queries in MySQL Monitorowanie zapytań SQL w MySQL

Microsoft's SQL Server has a tool called Profiler that you can use to monitor every SQL query that hits the database. Microsoft SQL Server jest narzędzie o nazwie Profiler, które można wykorzystać do monitorowania wszystkich zapytań SQL do bazy danych, aby wejść. This is extremely useful for programmers as well as database administrators to troubleshoot the exact queries generated by an application. Jest to bardzo przydatne dla programistów, jak i administratorzy baz danych, aby rozwiązać taką zapytania generowane przez aplikację.

Having switched to using MySQL on a frequent basis, this was one of the first things I wanted to figure out how to do. Po włączeniu do MySQL nie rzadziej, była to jedna z pierwszych rzeczy, chciałem dowiedzieć się jak to zrobić. How else can you see the actual SQL code generated by Wordpress or phpBB? Jak inaczej można zobaczyć faktyczny kod SQL generowany przez Wordpress czy phpBB?

The first thing we'll need to do is turn on logging of queries in MySQL. Pierwszą rzeczą jaką musimy zrobić, to włączyć rejestrowanie zapytania w MySQL. Be warned that this should only be done in development… it really slows things down to log every single query to a file. Ostrzegamy, że powinno to zostać dokonane jedynie w rozwoju ... naprawdę spowalnia rzeczy w dół rejestrować każde jedno zapytanie do pliku.

Find and open your MySQL configuration file, usually /etc/mysql/my.cnf on Ubuntu. Znajdź i otwórz plik konfiguracyjny MySQL, zwykle / etc / mysql / my.cnf w Ubuntu. Look for the section that says “Logging and Replication” Ta część, która mówi: "Rejestrowanie i Replication"

# #
# * Logging and Replication # * Rejestrowanie i replikacji
# #
# Both location gets rotated by the cronjob. # Both location gets obracane o cronjob.
# Be aware that this log type is a performance killer. # Należy pamiętać, że tego rodzaju dziennika jest zabójcą wydajności.

log = /var/log/mysql/mysql.log log = / var / log / mysql / mysql.log

Just uncomment the “log” variable to turn on logging. Po prostu usuń "log" zmienna, aby włączyć rejestrowanie. Restart MySQL with this command: Restart MySQL z tego polecenia:

sudo /etc/init.d/mysql restart sudo / etc / init.d / mysql restart

Now we're ready to start monitoring the queries as they come in. Open up a new terminal and run this command to scroll the log file, adjusting the path if necessary. Teraz jesteśmy gotowi do rozpoczęcia monitorowania zapytań, gdyż pochodzą in Otwórz nowy terminal i uruchomić to polecenie, aby przewijać plik dziennika, dostosowując ścieżkę, jeśli jest to konieczne.

tail -f /var/log/mysql/mysql.log tail-f / var / log / mysql / mysql.log

Now run your application. Teraz czas na uruchomienie aplikacji. You'll see the database queries start flying by in your terminal window. Zobaczysz zapytania do bazy danych przez lotny start w oknie terminala. (make sure you have scrolling and history enabled on the terminal) (upewnij się, że przewijanie i historii aktywny na terminalu)

I'm impressed, phpbb3 has fairly tight, optimized SQL code. Jestem pod wrażeniem, phpbb3 ma dość napięty, zoptymalizowany kod SQL. Wordpress, on the other hand, is very inefficient. Wordpress, z drugiej strony, jest bardzo nieefektywne.

This article was originally written on 05/16/07 Tagged with: Ten artykuł został napisany na 05/16/07 Tagged with: Database Baza danych

Daily Email Updates Daily Email Updates

You can get our how-to articles in your inbox each day for free. Możesz pobrać nasze instrukcje postępowania w skrzynce odbiorczej codziennie za darmo. Just enter your name and email below: Wystarczy podać swoje imię i adres e-mail:


Name: Imię i nazwisko:
Email: E-mail:

Comments (4) Komentarze (4)

  1. supermansghost supermansghost

    This is an awesome tip. To jest niesamowite końcówki.

  2. JTMcNaught JTMcNaught

    This is exactly what I needed to help me optimize my growing website. To jest dokładnie to, co potrzebne, aby mi pomóc zoptymalizować stronę internetową rośnie. Thanks to How-To-Geek, many hours of frustration of mine have been saved and now I can finally analyse the freqency and stress loads caused by all of the different queries hitting the MYSQL server and finally resolve some of the slowdowns and performance issues due to the load. Dzięki How-To-Geek, wiele godzin frustrację kopalni zostały zapisane i teraz mogę wreszcie analizować freqency obciążenia i stresu spowodowanego przez wszystkie inne zapytania uderzanie serwera MySQL i ostatecznie rozwiązać niektóre problemy z wydajnością i spowolnienie spowodowane do obciążenia.

    With appreciation! Z uznaniem!

    JTMcNaught JTMcNaught

  3. Alain Alain

    Thank you, I was trying to remember how to do this. Dziękuję, starałem się pamiętać, jak to zrobić.
    The information is concise and precise. Informacji jest zwięzły i precyzyjny. Right to the point. Prawo do pkt.

  4. Jaris Jaris

    Thank you! Dziękuję!
    Exactly what I needed! Exactly what I needed!


Our Friends Nasi Przyjaciele
Getting Started Pierwsze kroki


About How-To Geek O How-To Geek
What Is That Process? Co to jest proces?
svchost.exe svchost.exe
jusched.exe jusched.exe
dwm.exe dwm.exe
ctfmon.exe Gadu-Gadu
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.