Enable Logging of Slow Queries (Slow Query Log) in MySQL Database啟用日誌記錄慢查詢(慢速查詢日誌)在MySQL數據庫
One of the main requirements for a fast其中一個主要的要求,快速 web server Web服務器 is to has efficient and effective SQL statements or queries that are optimized.是有效率和有效的SQL語句或查詢優化。 Any non-optimal SQL (Structured Query Language) commands or statements that take too long or lengthy time to execute will use up a lot of system resources, causing任何非最優的SQL (結構化查詢語言)命令或聲明,時間過長或冗長的時間來執行,將佔用大量系統資源,造成 MySQL MySQL的 database to run slower, and then more and more queries backlogs queuing up, and when connection limit is reached, visitors are been denied or refused connection.數據庫運行慢,然後越來越多的疑問,積壓排隊,當連接到達上限,旅客被拒絕或拒絕連接。 In worst case scenario, your web server will go down as well, or continuously underperform.在最壞的情況下,您的Web伺服器將下降,以及,或不斷低於。 The case is especially true when you are using MyISAM table type which uses table-level locking instead of row-level locking in a high traffic website.案件,尤其是當您使用MyISAM表類型使用表級鎖定而不是行級鎖定在一個高流量的網站。
Sometime, a single SQL query may be the cause of all the server’s problems.有時,一個單一的SQL查詢,可能是造成所有服務器的問題。 MySQL has built-in functionality to capture slow query log or identify queries that are not optimal and take a long time to finish, which allows you to log all slow running queries which took over defined number of seconds to execute by MySQL database engine to a file. MySQL中有內建的功能,捕捉慢速查詢日誌或確定的查詢是不是最優的和需要很長的時間完成,它使您可以記錄所有的緩慢運行的查詢接管的定義多少秒執行,由MySQL數據庫引擎來一文件。 Slow query log is not activated or on by default MySQL installation, thus it is one of the less-used logs.慢速查詢日誌未啟動或在默認情況下, MySQL安裝,因此,這是一個較少用的記錄。
To enable slow query log, simply add the following line to MySQL configuration file (my.cnf or my.ini), and then restart the MySQL server:使緩慢查詢日誌,只需添加以下行到MySQL配置文件( my.cnf或my.ini ) ,然後重新啟動MySQL服務器:
log-slow-queries登錄慢的疑問
or或
log-slow-queries = [path to the log file]登錄慢的疑問= [記錄檔案的路徑]
Replace [path to the log file] with actual path to the slow query log file you want the MySQL to write the log to, which is the optional value.替換[記錄檔案的路徑]與實際的路徑,以慢速查詢日誌文件您想要MySQL的寫日誌,這是可選的價值。
Or you can start mysqld with with the –log-slow-queries[=file_name] option to enable the slow query log.或者您也可以啟動mysqld與同-日誌-慢-疑問[ = FILE_NAME的]選項,使慢速查詢日誌。 In both syntaxes, if not log file name is specified, the default name is host_name -slow.log, stored in the MySQL data file directory.在這兩個語法,如果不是日誌文件名稱是指定的,預設的名稱是host_name - slow.log ,儲存在MySQL的數據文件目錄。 If a filename is given, but not as an absolute pathname, the server writes the file in the data directory too.如果filename是給予,而不是作為一個絕對的路徑,服務器寫入文件中的數據目錄。
After enabling slow query log, MySQL will create, capture and log to the log file with all SQL statements that took more than long_query_time seconds to execute, which is by default set to 10 seconds.之後,使慢速查詢日誌, MySQL的創造,捕捉和記錄到日誌文件與所有的SQL語句了以上long_query_time秒來執行,這是默認設置為10秒。 The time to acquire the initial table locks is not counted as execution time.時間,取得初步表鎖定,是不是算為執行時間。 mysqld writes a statement to the slow query log after it has been executed and after all locks have been released, so log order might be different from execution order. mysqld寫了一個聲明,慢速查詢日誌後,它已被處決後,所有的鎖已被釋放,因此,記錄,以便可能有所不同,從執行秩序。
You can then examine all the SQL queries that took longer than the pre-defined number of seconds (10 seconds by default) in the host_name -slow.log, and then take the necessary steps to optimize the SQL statements.然後,您就可以檢查所有SQL查詢,需時較長,比預先定義多少秒( 10秒默認情況下) ,在host_name - slow.log ,然後採取必要步驟,以優化SQL語句。 The slow query log will tell you about what was time the query completed, how long the query took to run, how long it took to secure its locks, how many rows were sent back as a result, how many rows were examined to determine the result, which database was used, and the actual query itself.慢速查詢日誌會告訴你什麼時間,查詢完成後,多久,查詢了運行,經過多久才,以確保其安全鎖,有多少行被送回因此,有多少行檢查,以確定結果,數據庫使用,與實際查詢本身。 But bear in mind that a SQL query contained in the log may have already optimum, but executed slowly due to the system resources been used up by the actual slow statement that need to be fine tuned.但緊記, SQL查詢,包含在日誌中可能已經優化,但執行緩慢,由於系統資源被用罄的實際緩慢,聲明認為,必須罰款拭目以待。
IMPORTANT : This is a machine translated page which is provided "as is" without warranty. 重要說明 :這是一個機器翻譯網頁是“按原樣”提供的擔保。 Machine translation may be difficult to understand.機器翻譯可能很難理解。 Please refer to請參閱 original English article原來的英語文章 whenever possible.只要有可能。
Share and contribute or get technical support and help at分享和貢獻,或取得技術的支持和幫助,在 My Digital Life Forums 我的數字生活論壇 . 。
Related Articles相關文章
- Change or Set MySQL Long Query Time Value for log-slow-queries改變或設置MySQL的長期查詢時間價值為登錄慢的疑問
- Install Web Server in Windows XP with Apache2, PHP5 and MySQL4 - Part 4安裝Web服務器在Windows XP的Apache2 , php5和mysql4 -第4部分
- Change and Reset MySQL root Password改變和重置MySQL的root密碼
- How to Backup and Restore (Export and Import) MySQL Databases Tutorial如何備份和恢復(出口和進口)的MySQL數據庫補習
- WordPress MySQL SQL Query Error in WPDB Class在WordPress MySQL的SQL查詢錯誤在wpdb級
- You Are Not Authorized to Execute SQL Queries in vBulletin Maintenance您未獲授權執行SQL查詢在vbulletin維修
- MySQL Database Performance Tuning Best Practices Video Tutorial MySQL數據庫性能調整的最佳做法視頻教程
- Using PHP-MySQL Persistent Connections to Run WordPress Blog使用PHP - MySQL的持久連接運行的WordPress所博客
- How to Read MySQL Binary Log Files (BinLog) with mysqlbinlog如何閱讀MySQL的二進制日誌文件( binlog )與mysqlbinlog
- Fix for Munin MySQL Monitoring Plugin Graph Not Showing or Blank修復munin MySQL的監測插件圖無法顯示或空白

































January 23rd, 2007 00:22 2007年1月23日0時22分
[...] If you enable slow queries log of MySQL database server, you will notice that from the slow query log file contains only SQL statements and queries that took more than query_time of 10 seconds to execute or run. [ … … ]如果您啟用緩慢查詢日誌MySQL數據庫服務器,您會發現從慢速查詢日誌文件只包含SQL語句,並查詢了以上query_time 10秒執行或執行。 This is the default value or query time threshold for log_slow_queries function, which is 10 seconds.這是預設值或查詢的時間門檻, log_slow_queries功能,這是10秒。 10 seconds is way too long for a SQL query to complete, so the value may be too high to capture any meaningful data. 10秒的方式是太長, SQL查詢完成,所以該值可能過高,以捕獲任何有意義的數據。 You can alter or change the slow query time to lower value or number of seconds.你可以改變或改變緩慢,查詢時間,以較低的價值或數量秒。 You can set a new long_query_time in the MySQL configuration file, namely my.cnf or my.ini, normally located in /etc directory.您可以設定一個新的long_query_time在MySQL的配置文件,即my.cnf或my.ini ,通常位於在/ etc目錄。 Simply add the following line to the configuration file: [...]只需添加以下行配置文件: [ … … ]