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 לפקח על כל שאילתות SQL ב-MySQL

Microsoft's SQL Server has a tool called Profiler that you can use to monitor every SQL query that hits the database. SQL Server של מיקרוסופט יש כלי שנקרא Profiler בהן ניתן להשתמש כדי לפקח על כל שאילתת SQL שמכה את מסד הנתונים. This is extremely useful for programmers as well as database administrators to troubleshoot the exact queries generated by an application. זה מאוד שימושי עבור מתכנתים כמו גם מנהלי מסדי נתונים כדי לפתור את שאילתות המדויק הנוצר על ידי יישום.

Having switched to using MySQL on a frequent basis, this was one of the first things I wanted to figure out how to do. לאחר עבר באמצעות MySQL על בסיס תכופות, זה היה אחד הדברים הראשונים רציתי להבין איך לעשות. How else can you see the actual SQL code generated by Wordpress or phpBB? איך עוד אתה יכול לראות את קוד SQL בפועל שנוצר ע"י Wordpress או phpBB?

The first thing we'll need to do is turn on logging of queries in MySQL. הדבר הראשון אנחנו צריכים לעשות הוא להפעיל רישום של שאילתות ב-MySQL. Be warned that this should only be done in development… it really slows things down to log every single query to a file. להיות הזהיר כי זו צריכה להיעשות רק בפיתוח ... זה באמת מאט את הדברים להיכנס כל שאילתה אחת לקובץ.

Find and open your MySQL configuration file, usually /etc/mysql/my.cnf on Ubuntu. מצא לפתוח קובץ התצורה MySQL שלך, בדרך כלל / etc / MySQL my.cnf על אובונטו. Look for the section that says “Logging and Replication” חפש הסעיף אומר כי "התחברות ו שכפול"

# #
# * Logging and Replication # * התחברות ו שכפול
# #
# Both location gets rotated by the cronjob. # שניהם במיקום מקבל סובב ידי cronjob.
# Be aware that this log type is a performance killer. # היה מודע לכך כי זה סוג היומן הוא רוצח ביצועים.

log = /var/log/mysql/mysql.log יומן = / var / log / MySQL / mysql.log

Just uncomment the “log” variable to turn on logging. רק uncomment את יומן "" משתנה כדי להפעיל כניסה. Restart MySQL with this command: הפעל מחדש את MySQL עם הפקודה הזאת:

sudo /etc/init.d/mysql restart / etc sudo / init.d / mysql מחדש

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. כעת אנו מוכנים להתחיל לפיקוח על שאילתות כפי שהם נכנסים תפתח מסוף חדש הפעלת פקודה זו כדי לגלול את קובץ היומן, התאמת את הנתיב במידת הצורך.

tail -f /var/log/mysql/mysql.log זנב-F / var / log / MySQL / mysql.log

Now run your application. כעת להפעיל את הבקשה שלך. You'll see the database queries start flying by in your terminal window. תראה את השאילתות על מסד הנתונים התחלה מצוינת מאת בחלון המסוף שלך. (make sure you have scrolling and history enabled on the terminal) (לוודא שיש לך גלילה ההיסטוריה מופעלת על המסוף)

I'm impressed, phpbb3 has fairly tight, optimized SQL code. אני מתרשם, phpBB3 יש די חזק, אופטימיזציה קוד SQL. Wordpress, on the other hand, is very inefficient. וורדפרס, לעומת זאת, הוא מאוד לא יעיל.

This article was originally written on 05/16/07 Tagged with: מאמר זה נכתב במקור ב 05/16/07 עם שתייגת: Database מסד הנתונים

Daily Email Updates שערי עדכונים בדוא"ל

You can get our how-to articles in your inbox each day for free. אתה יכול לקבל כמה שלנו למאמרים לתיבת הדואר שלך בכל יום בחינם. Just enter your name and email below: פשוט להזין את שם ואת הדוא"ל שלך להלן:


Name: שם:
Email: דואר אלקטרוני:

Comments (4) תגובות (4)

  1. supermansghost supermansghost

    This is an awesome tip. זהו טיפ מדהים.

  2. JTMcNaught JTMcNaught

    This is exactly what I needed to help me optimize my growing website. זה בדיוק מה שהייתי צריכה לעזור לי אופטימיזציה לאתר שלי גדל. 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. הודות How-to-חנון, שעות רבות של תסכול שלי נשמרו ועכשיו סוף סוף אני יכול לנתח את freqency ומתחים טוען שנגרמו על ידי כל שאילתות שונות להכות את השרת MySQL ו לבסוף לפתור חלק של האטה ובעיות הביצועים בשל כדי לטעון את.

    With appreciation! בהוקרה!

    JTMcNaught JTMcNaught

  3. Alain אלן

    Thank you, I was trying to remember how to do this. תודה לך, אני מנסה להיזכר איך לעשות את זה.
    The information is concise and precise. המידע הוא תמציתי ומדויק. Right to the point. ישר לעניין.

  4. Jaris Jaris

    Thank you! תודה!
    Exactly what I needed! בדיוק מה שהייתי צריכה!


Leave a Comment השאירו תגובה




Leave your השאירו שלך friendly ידידותי comment here. תגובה כאן.

If you have a computer help question, אם יש לך מחשב לעזור השאלה, click here to leave it on the forums לחץ כאן כדי להשאיר אותו על פורומים instead. במקום.

Note: Your comment may not show up immediately on the site. הערה: ההערה שלך לא תופיע מיד באתר.

Our Friends חברים שלנו
Getting Started התחלת העבודה


About How-To Geek אודות How-To Geek
What Is That Process? מה זה תהליך?
svchost.exe svchost.exe
jusched.exe jusched.exe
dwm.exe dwm.exe
ctfmon.exe Ctfmon.exe
wmpnetwk.exe wmpnetwk.exe
mDNSResponder.exe mDNSResponder.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. זכויות יוצרים © 2006-2009 HowToGeek.com. All Rights Reserved. כל הזכויות שמורות.