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[=
or debug_options]-# [
option. If you specify the debug_options]--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 macrost:跟踪函数调用和退出t: Trace function calls and exitsi:在输出行中添加 PIDi: Add PID to output lineso,/tmp/mysqld.trace,O,\mysqld.trace:设置调试输出文件。o,/tmp/mysqld.trace,O,\mysqld.trace: Set the debug output file.
大多数客户端程序使用默认的 debug_options 值 d:t:o,/tmp/,无论平台如何。Most client programs use a default
program_name.tracedebug_options value of
d:t:o,/tmp/,
regardless of platform.program_name.trace
以下是一些调试控制字符串示例,它们可能在命令行中指定: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 = 'mysql>debug_options';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 |
|---|---|
|
启用当前状态下来自 在 MySQL 中,常用的调试宏关键词包括 |
|
每行调试器输出后延迟。参数是延迟时间,单位为十分之一秒,受机器性能限制。例如, |
|
将调试、跟踪和性能分析限制在指定的命名函数列表中。空列表表示启用所有函数。仍然必须提供适当的 |
|
识别每行调试或追踪输出的源文件名。Identify the source file name for each line of debug or trace output. |
|
为每行调试或跟踪输出识别其对应的进程 ID 或线程 ID。Identify the process with the PID or thread ID for each line of debug or trace output. |
|
为每行调试或追踪输出识别源文件行号。Identify the source file line number for each line of debug or trace output. |
|
打印每行调试或追踪输出的当前函数嵌套深度。Print the current function nesting depth for each line of debug or trace output. |
|
为每一行调试输出编号。Number each line of debug output. |
|
将调试器输出流重定向到指定的文件。默认输出是 |
|
类似于 |
|
类似于 |
|
类似于 |
|
将调试器操作限制为指定的进程。必须用 |
|
打印调试或跟踪输出每一行的当前进程名称。Print the current process name for each line of debug or trace output. |
|
在推送新状态时,不要继承之前状态的函数嵌套等级。当输出需要从左边距开始时,这很有用。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. |
|
启用函数调用/退出跟踪行。后面可以跟一个列表(仅包含一个修饰符),指定数字最大跟踪级别,超过该级别调试或跟踪宏都不会输出。默认值是编译时选项。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. |
|
为每一行输出打印当前时间戳。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 | +---------+ | | +---------+