Lab Environment:
OS X EI Captian + MySQL 5.7
I. Configure MySQL to automatically record slow query log
View variables, i.e. configuration information
show (global) variables like '%slow_query%'
To modify a variable:
set global 变量名 = 值
Variables related to the slow query log:
是否开启慢查询日志slow_query_log = OFF long_query_time = 10 最大时间限制,超过此时间,再记录slow_query_log_file = /usr/slow.log日志文件位置log_queries_not_using_indexes = OFF没有使用索引的搜索是否记录
Let's start with the slow query log:
?
Modify Query Time:
?
There are two global variables left, and log paths and records with no indexes are the default values.
Second, check the MySQL slow query log
Can be viewed directly:
vim /usr/local/var/mysql/DyanLideMacBook-Air-slow.log
?
You can also use the mysqldumpslow
view slow query log:
mysqldumpslow -s at -a /usr/local/var/mysql/DyanLideMacBook-Air-slow.log
View Help mysqldumpslow --help
:
?
Translation of several commonly used:
--verbose 版本--debug 调试--help 帮助 -v 版本-d 调试模式-s ORDER 排序方式 al: average lock time ar: average rows sent at: average query time 默认 c: count l: lock time r: rows sent t: query time-r 反转顺序,默认文件倒序拍-t NUM 显示前N条-a 不要将SQL中数字转换成N,字符串转换成S-l 总时间中不减去锁定时间
MySQL Slow query log