Input command:show variables like ' slow% '
You can find that Slow_query_log is OFF (default), indicating that the slow query log is not turned on
Slow_query_log_file for slow query log file
There are two ways to turn on the slow query log
Method One: Temporarily open
Set Global slow_query_log = on;
#没有使用索引的sql将会被记录入慢查询日志
Set Global log_queries_not_using_indexes = on;
SQL #查询时间大于等于long_query_time (in seconds) will be logged into the slow query log
Set Global long_query_time = 1; # 1 means that SQL records greater than or equal to 1s are in the slow query log and can be changed to milliseconds or less
Method Two: Permanent Open
After you change the MySQL profile my.ini (Windows),[mysqld] , append the parameters in the red box:
Here Long_query_time = 0 means that all queries are logged to the slow query log, but the actual application should give a reasonable value in order to detect whether the configuration is in effect.
Save the configuration file and remember to restart Apache
When the slow query log is turned on, the SQL that is monitored is written to Slow_query_log_file , in the following format:
Since the slow query log is generated, of course, there are slow query log analysis tools , such as: MySQL comes with the Mysqldumpslow, there is not much to say.
Use the MySQL slow query log to monitor efficiency issues with SQL