Transferred from: http://www.cnblogs.com/gzgccsu/archive/2013/01/23/2873598.html
1. What is the use of slow queries?
It records all SQL statements that execute more than long_query_time time, helping you to find SQL that executes slowly, so we can optimize these SQL.
2. How do I turn on slow queries?
First we check if the MySQL server's slow query status is turned on. Execute the following command:
We can see that the current log_slow_queries status is off, indicating that no slow query is currently turned on.
It is very simple to turn on slow queries, as follows:
Find MySQL configuration file under Linux My.ini, add the configuration statement of slow query under MYSQLD (Note: Be sure to add below [mysqld]) "Mysqld server-side Configuration"
Log-slow-queries: On behalf of the MySQL slow query log storage directory, this directory file must have write permission;
You need to write an absolute path under Windows, such as: log-slow-queries= "C:/Program files/mysql/mysql Server 5.5/log/mysql-slow.log"
Long_query_time: Maximum execution time. (, MSYQL will record all the execution time more than 2 SQL statements, here is the test time, the time should not be too small preferably within 5-10 seconds, of course, according to their own standards);
Configure to restart a MySQL service later
Note: Turning on slow queries will have a performance impact and can be turned on for tuning. Logging slow SQL can also be implemented in the program. Use the time difference before and after SQL to log the SQL that is running slowly.
MySQL Slow query