文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 6 个 MySQL 程序 / 6.6 管理和实用程序 / 6.6.10 mysqldumpslow — 汇总慢查询日志文件
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 79%

6.6.10 mysqldumpslow — 汇总慢查询日志文件6.6.10 mysqldumpslow — Summarize Slow Query Log Files

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

  • --help

    命令行格式Command-Line Format --help--help

    显示帮助信息并退出。Display a help message and exit.

  • -a

    不要将所有数字抽象为 N,字符串抽象为 'S'。Do not abstract all numbers to N and 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 using WITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.

  • -g pattern -g pattern

    类型Type 字符串String

    仅考虑匹配 (grep-风格) 模式的查询。Consider only queries that match the (grep-style) pattern.

  • -h host_name -h host_name

    类型Type 字符串String
    默认值Default Value *

    MySQL 服务器的主机名,用于 *-slow.log 文件名。该值可以包含通配符。默认值是 *(匹配所有)。Host name of MySQL server for *-slow.log file name. The value can contain a wildcard. The default is * (match all).

  • -i name -i name

    类型Type 字符串String

    服务器实例的名称(如果使用 mysql.server 启动脚本)。Name of server instance (if using mysql.server startup script).

  • -l

    不要从总时间中扣除锁定时间。Do not subtract lock time from total time.

  • -n N

    类型Type 数字Numeric

    对名称中至少包含 N 位数字的数字进行抽象处理。Abstract numbers with at least N digits within names.

  • -r

    反转排序顺序。Reverse the sort order.

  • -s sort_type

    类型Type 字符串String
    默认值Default Value atat

    如何对输出进行排序。sort_type 的值应从以下列表中选择:How to sort the output. The value of sort_type should be chosen from the following list:

    • t, at:按查询时间或平均查询时间排序t, at: Sort by query time or average query time

    • l, al:按锁定时间或平均锁定时间排序l, al: Sort by lock time or average lock time

    • r, ar:按发送行数或平均发送行数排序r, ar: Sort by rows sent or average rows sent

    • c:按计数排序c: Sort by count

    默认情况下,mysqldumpslow 按平均查询时间排序(等同于 -s at)。By default, mysqldumpslow sorts by average query time (equivalent to -s at).

  • -t N

    类型Type 数字Numeric

    在输出中仅显示前 N 条查询。Display only the first N queries in the output.

  • --verbose, -v --verbose, -v

    命令行格式Command-Line Format --verbose--verbose

    详细模式。打印有关程序执行内容的更多信息。Verbose mode. Print more information about what the program does.