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 Övervakar alla SQL-frågor i MySQL

Microsoft's SQL Server has a tool called Profiler that you can use to monitor every SQL query that hits the database. Microsofts SQL Server är ett verktyg som heter Profiler som du kan använda för att övervaka varje SQL-uttryck som träffar i databasen. This is extremely useful for programmers as well as database administrators to troubleshoot the exact queries generated by an application. Detta är mycket användbart för programmerare samt databasadministratörer att felsöka den exakta frågor som genereras av en ansökan.

Having switched to using MySQL on a frequent basis, this was one of the first things I wanted to figure out how to do. Efter att ha bytt till att använda MySQL på regelbundna, var detta en av de första saker jag ville ta reda på hur man gör. How else can you see the actual SQL code generated by Wordpress or phpBB? Hur kan man annars se det faktiska SQL-kod som genereras av Wordpress och phpBB?

The first thing we'll need to do is turn on logging of queries in MySQL. Det första vi behöver göra är att aktivera loggning av frågor i MySQL. Be warned that this should only be done in development… it really slows things down to log every single query to a file. Varnas för att detta endast bör ske i utvecklingen ... det verkligen saktar ner saker för att registrera varje enskild fråga till en fil.

Find and open your MySQL configuration file, usually /etc/mysql/my.cnf on Ubuntu. Hitta och öppna din MySQL konfigurationsfil, vanligtvis / etc / mysql / my.cnf på Ubuntu. Look for the section that says “Logging and Replication” Sök efter avsnittet som heter "loggning och Replication"

# #
# * Logging and Replication # * Loggning och replikering
# #
# Both location gets rotated by the cronjob. # Båda plats blir roteras av cronjob.
# Be aware that this log type is a performance killer. # Var medveten om att denna logg är en föreställning mördare.

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

Just uncomment the “log” variable to turn on logging. Just avkommentera "log" variabel för att slå på loggning. Restart MySQL with this command: Starta MySQL med detta kommando:

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

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. Nu är vi redo att börja övervaka frågor allteftersom de kommer in Öppna upp en ny terminal och kör detta kommando för att bläddra loggfilen, anpassa sökvägen om det behövs.

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

Now run your application. Nu kör programmet. You'll see the database queries start flying by in your terminal window. Du kommer att se databasfrågor börja flyga med i ditt terminalfönster. (make sure you have scrolling and history enabled on the terminal) (Se till att du har rullning och historia aktiverat på terminalen)

I'm impressed, phpbb3 has fairly tight, optimized SQL code. Jag är imponerad, phpbb3 har ganska snäv, optimerad SQL-kod. Wordpress, on the other hand, is very inefficient. Wordpress, å andra sidan, är mycket ineffektivt.

This article was originally written on 05/16/07 Tagged with: Denna artikel skrevs ursprungligen på 05/16/07 Märkta med: Database Databas

Daily Email Updates Dagligt Updates

You can get our how-to articles in your inbox each day for free. Du kan få våra instruktioner artiklar i din inkorg varje dag gratis. Just enter your name and email below: Skriv bara in ditt namn och e-postadress nedan:


Name: Namn:
Email: Email:

Comments (4) Kommentarer (4)

  1. supermansghost supermansghost

    This is an awesome tip. Detta är en fantastisk spets.

  2. JTMcNaught JTMcNaught

    This is exactly what I needed to help me optimize my growing website. Detta är precis vad jag behövde för att hjälpa mig optimera min växande webbplats. 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. Tack vare How-To-, Geek har många timmar av frustration av mina sparats och nu kan jag äntligen analysera freqency och stress laster som orsakas av alla de olika frågor som träffar MySQL-servern och slutligen lösa några av avmattning och prestanda på grund till lasten.

    With appreciation! Med glädje!

    JTMcNaught JTMcNaught

  3. Alain Alain

    Thank you, I was trying to remember how to do this. Tack, jag försökte komma ihåg hur man gör detta.
    The information is concise and precise. Informationen är kortfattad och tydlig. Right to the point. Rakt på sak.

  4. Jaris Jaris

    Thank you! Tack!
    Exactly what I needed! Precis vad jag behövde!


Leave a Comment Lämna en kommentar




Leave your Lämna ditt friendly friendly comment here. kommentar här.

If you have a computer help question, Om du har en dator hjälp fråga, click here to leave it on the forums Klicka här för att lämna det i forumen instead. istället.

Note: Your comment may not show up immediately on the site. Obs: Din kommentar inte får visa upp omedelbart på platsen.

Our Friends Our Friends
Getting Started Komma igång


About How-To Geek Om How-To Geek
What Is That Process? Hur skall den processen?
svchost.exe svchost.exe
jusched.exe SynTPEnh.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.