MySQL 慢查询日志包含有关执行时间较长查询的信息(参见 第 7.4.5 节,“慢查询日志”)。mysqldumpslow 解析 MySQL 慢查询日志文件并汇总其中的内容。The MySQL slow query log contains information about queries that take a long time to execute (see Section 7.4.5, “The Slow Query Log”). mysqldumpslow parses MySQL slow query log files and summarizes their contents.
通常,mysqldumpslow 会将查询进行分组,分组依据是查询相似,但数值和字符串数据的具体值不同。它在显示汇总输出时会将这些值“抽象化”为N和'S'。要修改值抽象化行为,请使用-a和-n选项。Normally, mysqldumpslow groups queries that
are similar except for the particular values of number and
string data values. It “abstracts” these values to
N and 'S' when displaying
summary output. To modify value abstracting behavior, use the
-a and -n options.
像这样调用mysqldumpslow:Invoke mysqldumpslow like this:
mysqldumpslow [options] [log_file...]
没有提供选项的示例输出:Example output with no options given:
Reading mysql slow query log from /usr/local/mysql/data/mysqld84-slow.log Count: 1 Time=4.32s (4s) Lock=0.00s (0s) Rows=0.0 (0), root[root]@localhost insert into t2 select * from t1 Count: 3 Time=2.53s (7s) Lock=0.00s (0s) Rows=0.0 (0), root[root]@localhost insert into t2 select * from t1 limit N Count: 3 Time=2.13s (6s) Lock=0.00s (0s) Rows=0.0 (0), root[root]@localhost insert into t1 select * from t1
mysqldumpslow 支持以下选项。mysqldumpslow supports the following options.
表 6.21 mysqldumpslow 选项Table 6.21 mysqldumpslow Options
| 选项名称Option Name | 说明Description |
|---|---|
| -a | 不要把所有数字抽象为 N,字符串抽象为 'S'Do not abstract all numbers to N and strings to 'S' |
| -n | 具有至少指定位数的抽象数字Abstract numbers with at least the specified digits |
| --调试--debug | 写入调试信息Write debugging information |
| -g | 只考虑符合模式的语句Only consider statements that match the pattern |
| --帮助--help | 显示帮助信息并退出Display help message and exit |
| -h | 日志文件名中的服务器主机名Host name of the server in the log file name |
| -i | 服务器实例名称Name of the server instance |
| -l | 不要从总时间中扣除锁定时间Do not subtract lock time from total time |
| -r | 反转排序顺序Reverse the sort order |
| -s | 如何排序输出How to sort output |
| -t | 仅显示前 num 个查询Display only first num queries |
| --详细模式--verbose | 详细模式Verbose mode |
命令行格式Command-Line Format --help--help显示帮助信息并退出。Display a help message and exit.
不要将所有数字抽象为
N,字符串抽象为'S'。Do not abstract all numbers toNand strings to'S'.--debug,-d命令行格式Command-Line Format --debug以调试模式运行。Run in debug mode.
此选项仅在 MySQL 使用
WITH_DEBUG构建时可用。Oracle 提供的 MySQL 发行版二进制文件 未 使用此选项构建。This option is available only if MySQL was built usingWITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.类型Type 字符串String 仅考虑匹配 (grep-风格) 模式的查询。Consider only queries that match the (grep-style) pattern.
类型Type 字符串String 默认值Default Value *MySQL 服务器的主机名,用于
*-slow.log文件名。该值可以包含通配符。默认值是*(匹配所有)。Host name of MySQL server for*-slow.logfile name. The value can contain a wildcard. The default is*(match all).类型Type 字符串String 服务器实例的名称(如果使用 mysql.server 启动脚本)。Name of server instance (if using mysql.server startup script).
不要从总时间中扣除锁定时间。Do not subtract lock time from total time.
类型Type 数字Numeric 对名称中至少包含
N位数字的数字进行抽象处理。Abstract numbers with at leastNdigits within names.反转排序顺序。Reverse the sort order.
类型Type 字符串String 默认值Default Value atat如何对输出进行排序。
sort_type的值应从以下列表中选择:How to sort the output. The value ofsort_typeshould be chosen from the following list:t,at:按查询时间或平均查询时间排序t,at: Sort by query time or average query timel,al:按锁定时间或平均锁定时间排序l,al: Sort by lock time or average lock timer,ar:按发送行数或平均发送行数排序r,ar: Sort by rows sent or average rows sentc:按计数排序c: Sort by count
默认情况下,mysqldumpslow 按平均查询时间排序(等同于
-s at)。By default, mysqldumpslow sorts by average query time (equivalent to-s at).类型Type 数字Numeric 在输出中仅显示前
N条查询。Display only the firstNqueries in the output.命令行格式Command-Line Format --verbose--verbose详细模式。打印有关程序执行内容的更多信息。Verbose mode. Print more information about what the program does.