在[mysqld]下添加:
log_slow_queries = ON
long_query_time = 3
log-slow-queries = /usr/local/mysql/slow-queries.log
# long_query_time设置执行超过时间(秒)
# log-slow-queries 设置日志路径,为空时系统会给一个缺省的文件host_name-slow.log,生成的日志就在mysql的data目录下
mysqldumpslow 以下为mysqldumpslow -h 的参数
-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
-a don't abstract all numbers to N and strings to 'S'
-n NUM abstract numbers with at least n digits within names
-g PATTERN grep: only consider stmts that include this 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
# -s,是表示按照何种方式排序,c、t、l、r分别是按照记录次数、时间、查询时间、返回的记录数来排序(从大到小),ac、at、al、ar表示相应的倒叙。
# -t,是top n的意思,即为返回前面多少条数据。
# -g,后边可以写一个正则匹配模式,大小写不敏感。
例子:列出记录中最多的8个sql语句
mysqldumpslow -s t -t 8 slow-queries.log
















