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
- How to Bypass and Stop Automatic Logon to Log On as Different User如何绕道和停止自动登录登录为不同的用户



















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