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 我的數字生活論壇 .



One Response to “Enable Logging of Slow Queries (Slow Query Log) in MySQL Database” 1回應“啟用日誌記錄慢查詢(慢速查詢日誌)在MySQL數據庫”

  1. Change or Set MySQL Long Query Time Value for log-slow-queries » My Digital Life改變或設置MySQL的長期查詢時間價值為登錄慢的疑問»我的數位生活
    January 23rd, 2007 00:22 2007年1月23日0時22分
    1

    [...] 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: [...]只需添加以下行配置文件: [ … … ]

Leave a Reply離開的答复

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> 您可以使用這些標籤:的<a href="" title=""> <abbr title=""> <acronym title="">的<b> <blockquote cite=""> <cite>的<code> <刪除日期時間= “ ” >的<em>的<i> <q cite=""> <strike>的<strong>

Subscribe without commenting訂閱無評論


Custom Search

New Articles新的條款,

Incoming Search Terms for the Article傳入的搜索條件文章

enable slow query log 使緩慢查詢日誌 - - mysql enable Slow Query Log MySQL的啟用緩慢查詢日誌 - - slow query log 慢速查詢日誌 - - slow query log my.cnf 慢速查詢日誌my.cnf - - log slow queries 日誌緩慢的疑問 - - mysql slow query log my.cnf MySQL的緩慢查詢日誌my.cnf - - mysql turn on slow query log MySQL的開啟慢查詢日誌 - - my.cnf slow log my.cnf緩慢日誌 - - mysql slow query log MySQL的緩慢查詢日誌 - - slow query my.cnf 慢速查詢my.cnf - - enable mysql log 使MySQL的日誌 - - mysql enable query log MySQL中,使查詢日誌 - - how to enable slow query log 如何使慢速查詢日誌 - - Enable slow query 使慢速查詢 - - mysql long queries MySQL的長期疑問 - - my.cnf slow query my.cnf慢速查詢 - - my.ini slow query log my.ini緩慢查詢日誌 - - log-slow-queries 登錄慢的疑問 - - mysql enable log MySQL的啟用日誌 - - mysql enable slow query logging MySQL的啟用緩慢,查詢記錄 - - mysql log slow queries my.cnf MySQL的日誌緩慢疑問my.cnf - - mysql long query MySQL的長期查詢 - - mysql enable slow query log my.cnf MySQL的啟用緩慢查詢日誌my.cnf - - Enable the slow query log 使慢速查詢日誌 - - enable mysql logging 使MySQL的測井 - - log-slow-queries my.cnf 登錄慢的疑問my.cnf - - mysql query log MySQL查詢日誌 - - turn on slow query log 把對慢速查詢日誌 - - enable slow queries 使緩慢疑問 - - log-slow-queries my.ini 登錄慢的疑問my.ini - - mysql detect slow queries MySQL的檢測緩慢疑問 - - enable slow query log mysql 使緩慢查詢日誌的MySQL - - enable slow query logging 使慢速查詢記錄 - - mysql enable log my.ini MySQL的啟用日誌my.ini - - slow query log mysql my.cnf 慢速查詢日誌的MySQL my.cnf - - log slow query 日誌慢速查詢 - - mysql slow query log location MySQL的慢速查詢日誌位置 - - enable mysql query logging 使MySQL查詢記錄 - - mysql log sql queries MySQL的日誌SQL查詢 - - slow query logging 慢速查詢記錄 - - log all mysql queries that slow down 記錄所有的MySQL查詢放緩 - - mysql enable logs MySQL的啟用日誌 - - mysql turn on slow log MySQL的開啟緩慢日誌 - - mysql slow query MySQL的慢速查詢 - - mysql 4 slow query log MySQL的4緩慢查詢日誌 - - mysql long query time MySQL的長期查詢時間 - - mysql log slow queries MySQL的日誌緩慢的疑問 - - mysql my.ini log MySQL的my.ini日誌 - - mysql query log my.ini MySQL查詢日誌my.ini - - mysql logging turn on MySQL的記錄,從而對 - -