How to enable slow log query in MySQL
In Windows, find the my. ini file in the MySQL installation directory. The mysql version I use is earlier than 5.1.40.
Add the following lines in my. ini: MySQL Method for enabling slow log query
[Mysqld]
It is slow to define how many seconds the query has exceeded. Here I define 2 seconds
Long_query_time = 2
// 5.0, 5.1, and other versions are configured as follows
Define the Log Path for slow Query
Log-slow-queries = E:/mysqldb/mysqlslowquery. log
// 5.5 and later versions are configured as follows
Slow_query_log = ON
Slow_query_log_file = E:/mysqldb/slow_query_log.txt
The preceding configuration takes effect only when the mysql server process mysqld is restarted. You can also enable slow query logs dynamically.
View long_query_time
When the SQL statement runs beyond the value set by long_query_time, the statement is recorded in the slow query log. The unit of this parameter is seconds.
View slow_query_log Parameters
Set slow query:
Mysql> set global slow_query_log = on;
Mysql> set global long_query_time = 1;
Mysql> select sleep (2 );