8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 72%

7.9.4 DBUG 包7.9.4 The DBUG Package

MySQL 服务器和大多数 MySQL 客户端都是使用 Fred Fish 最初创建的 DBUG 软件包编译的。当你已将 MySQL 配置为调试模式时,这个软件包可以获取程序运行的跟踪文件。参见 第 7.9.1.2 节,“创建跟踪文件”。The MySQL server and most MySQL clients are compiled with the DBUG package originally created by Fred Fish. When you have configured MySQL for debugging, this package makes it possible to get a trace file of what the program is doing. See Section 7.9.1.2, “Creating Trace Files”.

本节总结了可以在命令行调试选项中为已启用调试支持的 MySQL 程序指定的参数值。This section summarizes the argument values that you can specify in debug options on the command line for MySQL programs that have been built with debugging support.

DBUG 包可以通过在程序中使用 --debug[=debug_options] 或 -# [debug_options] 选项来使用。如果您指定 --debug 或 -# 选项而没有 debug_options 值,大多数 MySQL 程序会使用默认值。服务器默认值在 Unix 上是 d:t:i:o,/tmp/mysqld.trace,在 Windows 上是 d:t:i:O,\mysqld.trace。此默认值的作用是:The DBUG package can be used by invoking a program with the --debug[=debug_options] or -# [debug_options] option. If you specify the --debug or -# option without a debug_options value, most MySQL programs use a default value. The server default is d:t:i:o,/tmp/mysqld.trace on Unix and d:t:i:O,\mysqld.trace on Windows. The effect of this default is:

  • d:启用所有调试宏的输出d: Enable output for all debug macros

  • t:跟踪函数调用和退出t: Trace function calls and exits

  • i:在输出行中添加 PIDi: Add PID to output lines

  • o,/tmp/mysqld.trace, O,\mysqld.trace:设置调试输出文件。o,/tmp/mysqld.trace, O,\mysqld.trace: Set the debug output file.

大多数客户端程序使用默认的 debug_options 值 d:t:o,/tmp/program_name.trace,无论平台如何。Most client programs use a default debug_options value of d:t:o,/tmp/program_name.trace, regardless of platform.

以下是一些调试控制字符串示例,它们可能在命令行中指定:Here are some example debug control strings as they might be specified on a shell command line:

--debug=d:t
--debug=d:f,main,subr1:F:L:t,20
--debug=d,input,output,files:n
--debug=d:t:i:O,\\mysqld.trace

对于 mysqld,也可以通过设置 debug 系统变量在运行时更改 DBUG 设置。该变量具有全局值和会话值:For mysqld, it is also possible to change DBUG settings at runtime by setting the debug system variable. This variable has global and session values:

mysql> SET GLOBAL debug = 'debug_options';
mysql> SET SESSION debug = 'debug_options';

更改全局 debug 值需要有足够的权限来设置全局系统变量。更改会话 debug 值需要有足够的权限来设置受限会话系统变量。请参阅 第 7.1.9.1 节,“系统变量权限”。Changing the global debug value requires privileges sufficient to set global system variables. Changing the session debug value requires privileges sufficient to set restricted session system variables. See Section 7.1.9.1, “System Variable Privileges”.

debug_options 的值是由冒号分隔的字段序列:The debug_options value is a sequence of colon-separated fields:

field_1:field_2:...:field_N

值中的每个字段由一个必需的标志字符组成,可选择在其前面添加 + 或 - 字符,也可选择在其后添加由逗号分隔的修饰符列表:Each field within the value consists of a mandatory flag character, optionally preceded by a + or - character, and optionally followed by a comma-separated list of modifiers:

[+|-]flag[,modifier,modifier,...,modifier]

下表描述了允许的标志字符。未识别的标志字符将被静默忽略。The following table describes the permitted flag characters. Unrecognized flag characters are silently ignored.

标志Flag

说明Description

d

启用当前状态下来自 DBUG_XXX 宏的输出。后面可以跟一个关键词列表,这样只会启用具有该关键词的 DBUG 宏的输出。关键词列表为空则启用所有宏的输出。Enable output from DBUG_XXX macros for the current state. May be followed by a list of keywords, which enables output only for the DBUG macros with that keyword. An empty list of keywords enables output for all macros.

在 MySQL 中,常用的调试宏关键词包括 enter、exit、error、warning、info 和 loop。In MySQL, common debug macro keywords to enable are enter, exit, error, warning, info, and loop.

D

每行调试器输出后延迟。参数是延迟时间,单位为十分之一秒,受机器性能限制。例如,D,20 指定延迟两秒。Delay after each debugger output line. The argument is the delay, in tenths of seconds, subject to machine capabilities. For example, D,20 specifies a delay of two seconds.

f

将调试、跟踪和性能分析限制在指定的命名函数列表中。空列表表示启用所有函数。仍然必须提供适当的d或t标志;此标志仅在启用这些操作时限制它们的行为。Limit debugging, tracing, and profiling to the list of named functions. An empty list enables all functions. The appropriate d or t flags must still be given; this flag only limits their actions if they are enabled.

F

识别每行调试或追踪输出的源文件名。Identify the source file name for each line of debug or trace output.

i

为每行调试或跟踪输出识别其对应的进程 ID 或线程 ID。Identify the process with the PID or thread ID for each line of debug or trace output.

L

为每行调试或追踪输出识别源文件行号。Identify the source file line number for each line of debug or trace output.

n

打印每行调试或追踪输出的当前函数嵌套深度。Print the current function nesting depth for each line of debug or trace output.

N

为每一行调试输出编号。Number each line of debug output.

o

将调试器输出流重定向到指定的文件。默认输出是 stderr。Redirect the debugger output stream to the specified file. The default output is stderr.

O

类似于 o,但在每次写入时文件会真正刷新。如有必要,文件在每次写入之间会关闭再重新打开。Like o, but the file is really flushed between each write. When needed, the file is closed and reopened between each write.

a

类似于 o,但以追加模式打开。Like o, but opens for append.

A

类似于 O,但以追加模式打开。Like O, but opens for append.

p

将调试器操作限制为指定的进程。必须用 DBUG_PROCESS 宏标识进程,并与列表中的某一项匹配,调试器操作才会发生。Limit debugger actions to specified processes. A process must be identified with the DBUG_PROCESS macro and match one in the list for debugger actions to occur.

P

打印调试或跟踪输出每一行的当前进程名称。Print the current process name for each line of debug or trace output.

r

在推送新状态时,不要继承之前状态的函数嵌套等级。当输出需要从左边距开始时,这很有用。When pushing a new state, do not inherit the previous state's function nesting level. Useful when the output is to start at the left margin.

t

启用函数调用/退出跟踪行。后面可以跟一个列表(仅包含一个修饰符),指定数字最大跟踪级别,超过该级别调试或跟踪宏都不会输出。默认值是编译时选项。Enable function call/exit trace lines. May be followed by a list (containing only one modifier) giving a numeric maximum trace level, beyond which no output occurs for either debugging or tracing macros. The default is a compile time option.

T

为每一行输出打印当前时间戳。Print the current timestamp for every line of output.

前导的 + 或 - 字符以及后续的修饰符列表用于标志字符,例如 d 或 f,它们可以为所有适用的修饰符或其中的一部分启用调试操作:The leading + or - character and trailing list of modifiers are used for flag characters such as d or f that can enable a debug operation for all applicable modifiers or just some of them:

  • 如果没有前导的 + 或 -,标志值将被设置为给定的修饰符列表。With no leading + or -, the flag value is set to exactly the modifier list as given.

  • 如果有前导的 + 或 -,列表中的修饰符将被添加到当前修饰符列表中或从当前修饰符列表中减去。With a leading + or -, the modifiers in the list are added to or subtracted from the current modifier list.

下面的示例展示了 d 标志的工作原理。空的 d 列表会启用所有调试宏的输出。非空列表仅会启用列表中宏关键字的输出。The following examples show how this works for the d flag. An empty d list enabled output for all debug macros. A nonempty list enables output only for the macro keywords in the list.

这些语句将 d 值设置为给定的修改器列表:These statements set the d value to the modifier list as given:

mysql> SET debug = 'd';
mysql> SELECT @@debug;
+---------+
| @@debug |
+---------+
| d       |
+---------+
mysql> SET debug = 'd,error,warning';
mysql> SELECT @@debug;
+-----------------+
| @@debug         |
+-----------------+
| d,error,warning |
+-----------------+

前导的 + 或 - 分别增加或减少当前的 d 值:A leading + or - adds to or subtracts from the current d value:

mysql> SET debug = '+d,loop';
mysql> SELECT @@debug;
+----------------------+
| @@debug              |
+----------------------+
| d,error,warning,loop |
+----------------------+

mysql> SET debug = '-d,error,loop';
mysql> SELECT @@debug;
+-----------+
| @@debug   |
+-----------+
| d,warning |
+-----------+

对 “启用所有宏” 的增加不会产生任何变化:Adding to “all macros enabled” results in no change:

mysql> SET debug = 'd';
mysql> SELECT @@debug;
+---------+
| @@debug |
+---------+
| d       |
+---------+

mysql> SET debug = '+d,loop';
mysql> SELECT @@debug;
+---------+
| @@debug |
+---------+
| d       |
+---------+

禁用所有已启用的宏将完全禁用 d 标志:Disabling all enabled macros disables the d flag entirely:

mysql> SET debug = 'd,error,loop';
mysql> SELECT @@debug;
+--------------+
| @@debug      |
+--------------+
| d,error,loop |
+--------------+

mysql> SET debug = '-d,error,loop';
mysql> SELECT @@debug;
+---------+
| @@debug |
+---------+
|         |
+---------+