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 - - my.cnf slow log my.cnf缓慢日志 - - log slow queries 日志缓慢的疑问 - - mysql long queries MySQL的长期疑问 - - mysql slow query log MySQL的缓慢查询日志 - - my.ini slow query log my.ini缓慢查询日志 - - enable mysql log 使MySQL的日志 - - slow query my.cnf 慢速查询my.cnf - - mysql enable slow query logging MySQL的启用缓慢,查询记录 - - mysql enable query log MySQL中,使查询日志 - - mysql turn on slow query log MySQL的开启慢查询日志 - - Enable slow query 使慢速查询 - - mysql enable slow query log my.cnf MySQL的启用缓慢查询日志my.cnf - - my.cnf slow query my.cnf慢速查询 - - mysql log slow queries my.cnf MySQL的日志缓慢疑问my.cnf - - mysql slow query log my.cnf MySQL的缓慢查询日志my.cnf - - how to enable slow query log 如何使慢速查询日志 - - mysql long query MySQL的长期查询 - - log-slow-queries 登录慢的疑问 - - mysql enable log MySQL的启用日志 - - log slow query 日志慢速查询 - - mysql query log MySQL查询日志 - - enable mysql query logging 使MySQL查询记录 - - mysql log sql queries MySQL的日志SQL查询 - - log all mysql queries that slow down 记录所有的MySQL查询放缓 - - mysql enable logs MySQL的启用日志 - - mysql turn on slow log MySQL的开启缓慢日志 - - log-slow-queries my.ini 登录慢的疑问my.ini - - mysql slow query MySQL的慢速查询 - - mysql detect slow queries MySQL的检测缓慢疑问 - - mysql log slow queries MySQL的日志缓慢的疑问 - - Enable the slow query log 使慢速查询日志 - - enable mysql logging 使MySQL的测井 - - mysql query log my.ini MySQL查询日志my.ini - - mysql logging turn on MySQL的记录,从而对 - - mysql long query log MySQL的长期查询日志 - - slow query log mysql my.cnf 慢速查询日志的MySQL my.cnf - - my.ini long query time my.ini ,只要查询时间 - - MySQL slow queries my.ini MySQL的缓慢查询my.ini - - my.cnf query log my.cnf查询日志 - - enable slow query in mysql 使慢速查询在MySQL - - Query taking more than the threshold time, execution time = 92 secs. 查询采取较阈值的时间,执行时间= 92秒。 - - log-slow-queries my.cnf 登录慢的疑问my.cnf - - mysql log slow queries my.ini MySQL的日志缓慢疑问my.ini - - mysql slow query log location MySQL的慢速查询日志位置 - - slow query logging 慢速查询记录 - - turn on slow query log 把对慢速查询日志 - -