To view the current slow-scan log status:
Show variables like '%slow% '; #主要关注三个变量: Slow_query_log #是否启用slow_query_log_file #日志文件 # time threshold for slow check show variables like ' Long_ Query_time ';
To configure the Enable slow scan log:
# # Vim My.cnf:slow_query_log=1slow_query_log_file=/var/log/mysql/slow.log #需要新建该文件, and note the file's read and Write permissions long_query_time = 2## You can switch configuration under current connection, Mysql Shell execution: Set long_query_time = 5 #临时调整当前连接慢查询的阈值, does not affect other connection thresholds set global slow_query_log=0 #全局关闭 slow log. (MySQL enforces this as a global configuration) #关闭状态持续至手动切回开启
To view the slow-scan log:
The way to view log files directly is laborious, but MySQL provides simple log analysis tools Mysqldumpslow
Mysqldumpslow "Options" log_file option:-S order #以什么排序 (Al, at, AR, AE, C, L, R, E, T) #at (average query time, default), AL (Average lock time), AR (average Off count) #c (Record Count), L (lock time), R (transmission line number), T (query time)-R #倒序-T #显示几条慢查询-G pattern #搜索关键字
MySQL Slow check log