To see if the MySQL server's slow query status is turned on:
1 |
show variables like '%slow%' ; |
- Slow_launch_time, which means more than 2 seconds is defined as a slow query
- Log_slow_queries and Slow_query_log, indicating that the slow query has been opened
- Slow_query_log_file, the location of the file that represents the slow query log
In the MySQL configuration file my.cnf or my.ini [mysqld] Add the slow query configuration statement settings to open the slow query state :
3 |
#定义慢查询日志路径(此目录文件一定要有写权限) |
4 |
log-slow-queries=C:/slowquery.log |
6 |
log-queries-not-using-indexes |
Once configured, restart MySQL, the MySQL server's slow query status has been opened:
Of course, you can also use the SET command to set the state of a MySQL variable, but this setting is temporary:
1 |
set global slow_query_log= on ; #开启 |
2 |
set global slow_query_log= off ; #关闭 |
Precautions:
Slow query time should not be set too long, otherwise not very meaningful