Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

5.11.5. The Slow Query Log

The slow query log consists of all SQL statements that took more than long_query_time seconds to execute. The time to acquire the initial table locks is not counted as execution time. The minimum and default values of long_query_time are 1 and 10, respectively.

mysqld writes a statement to the slow query log after it has been executed and after all locks have been released. Log order may be different from execution order.

To enable the slow query log as of MySQL 5.1.6, start mysqld with the --log-slow-queries option, and optionally use --log-output to specify the log output destination as described in Section 5.11.1, “Server Log Tables”. Before 5.1.6, enable the slow query log file with the --log-slow-queries[=file_name] option. If no file_name value is given, the default is the name of the host machine with a suffix of -slow.log. If a filename is given, but not as an absolute pathname, the server writes the file in the data directory.

The slow query log can be used to find queries that take a long time to execute and are therefore candidates for optimization. However, examining a long slow query log can become a difficult task. To make this easier, you can process the slow query log using the mysqldumpslow command to summarize the queries that appear in the log. Use mysqldumpslow --help to see the options that this command supports.

In MySQL 5.1, slow queries that do not use indexes are logged as well as those that do. To prevent queries that do not use indexes from being logged in the slow query log, use the --log-queries-not-using-indexes option. See Section 5.2.1, “mysqld Command Options”.

In MySQL 5.1, the --log-slow-admin-statements server option enables you to request logging of slow administrative statements such as OPTIMIZE TABLE, ANALYZE TABLE, and ALTER TABLE to the slow query log.

Queries handled by the query cache are not added to the slow query log, nor are queries that would not benefit from the presence of an index because the table has zero rows or one row.


 
 
  Published under the terms of the GNU General Public License Design by Interspire