MySQL自带的slow log分析工具mysqldumpslow

来源:百度文库 编辑:神马文学网 时间:2024/04/27 21:10:39
发表于  2005-07-23    作者:不详   出自 网络收集    点击: 1324
MySQL自带的slow log分析工具mysqldumpslow
MySQL自带slow log的分析工具mysqldumpslow,但是没有说明。本文通过分析该脚本,介绍了其用法。slow log是MySQL根据SQL语句的执行时间设定,写入的一个文件,用于分析执行较慢的语句。
只要在 my.cnf 文件中配置好:
log-slow-queries = [slow_query_log_filename]
即可记录超过默认的 10s 执行时间的 SQL 语句。
如果要修改默认设置,可以添加:
long_query_time = 5
设定为 5s 。
如果要记录所有 SQL 语句,可以写入:
log-long-format
# t=time, l=lock time, r=rows
# at, al, 以及 ar 是对应的平均值
mysqldumpslow 可以接受的参数有:
‘v+‘,              # verbose
‘d+‘,              # debug
‘s=s‘,             # 排序 (t, at, l, al, r, ar etc)
‘r!‘,               # 倒排序 (largest last instead of first)
‘t=i‘,              # 显示最高的 n 个查询
‘a!‘,               # 不把所有的数字以 N ,字符串以 ‘S‘ 显示
‘n=i‘,              # abstract numbers with at least n digits within names
‘g=s‘,            # grep: only consider stmts that include this string
‘h=s‘,            # hostname of db server for *-slow.log filename (can be wildcard)
‘i=s‘,             # name of server instance (if using mysql.server startup script)
‘l!‘,               # don‘t subtract lock time from total time