vim my.conf
log-queries-not-using-indexes = 0 #把慢查询以及执行时没有使用索引的查询命令全都记入日志(其余同--log-slow-queries选项)。
slow-query-log = 1
long_query_time = 2 #慢查询的执行用时上限(默认设置是10s)。
slow-query-log-file = /data/mysql/mysql-slow.log
show variables like “%slow%”; #查看慢查询配置
--verbose verbose
--debug debug
--help write this text to standard output
-v verbose
-d debug
-s ORDER what to sort by (al, at, ar, c, l, r, t), 'at' is default //排序 常用
al: average lock time
ar: average rows sent
at: average query time
c: count
l: lock time
r: rows sent
t: query time
-r reverse the sort order (largest last instead of first)//逆序
-t NUM just show the top n queries //top NUM 常用
-a don't abstract all numbers to N and strings to 'S' //不使用N S来代替‘变量’
-n NUM abstract numbers with at least n digits within names
-g PATTERN grep: only consider stmts that include this string // grep ‘string’常用
-h HOSTNAME hostname of db server for *-slow.log filename (can be wildcard),
default is '*', i.e. match all
-i NAME name of server instance (if using mysql.server startup script)
-l don't subtract lock time from total time
mysqldumpslow -s t -t 10 -a -g "like" /log/mysql/slowbak.log #按查询时间排序 包括like字符的前十个