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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

7.1.3 服务器配置验证7.1.3 Server Configuration Validation

MySQL 支持一个 --validate-config 选项,该选项允许在不以正常操作模式运行服务器的情况下检查启动配置是否存在问题:MySQL supports a --validate-config option that enables the startup configuration to be checked for problems without running the server in normal operational mode:

mysqld --validate-config

如果没有发现错误,服务器将以退出代码 0 终止。如果发现错误,服务器会显示诊断信息并以退出代码 1 终止。例如:If no errors are found, the server terminates with an exit code of 0. If an error is found, the server displays a diagnostic message and terminates with an exit code of 1. For example:

$> mysqld --validate-config --no-such-option
2018-11-05T17:50:12.738919Z 0 [ERROR] [MY-000068] [Server] unknown
option '--no-such-option'.
2018-11-05T17:50:12.738962Z 0 [ERROR] [MY-010119] [Server] Aborting

服务器在发现任何错误时会立即终止。若要进行额外检查,请先纠正初始问题,然后再次使用 --validate-config 启动服务器。The server terminates as soon as any error is found. For additional checks to occur, correct the initial problem and run the server with --validate-config again.

对于前述示例,当使用 --validate-config 时显示错误信息,服务器的退出代码为 1。根据 log_error_verbosity 的值,可能还会显示警告和信息消息,但不会导致立即验证终止或返回退出码 1。例如,该命令会产生多个警告,并且全部显示。但没有发生错误,因此退出代码为 0:For the preceding example, where use of --validate-config results in display of an error message, the server exit code is 1. Warning and information messages may also be displayed, depending on the log_error_verbosity value, but do not produce immediate validation termination or an exit code of 1. For example, this command produces multiple warnings, both of which are displayed. But no error occurs, so the exit code is 0:

$> mysqld --validate-config --log_error_verbosity=2
         --read-only=s --transaction_read_only=s
2018-11-05T15:43:18.445863Z 0 [Warning] [MY-000076] [Server] option
'read_only': boolean value 's' was not recognized. Set to OFF.
2018-11-05T15:43:18.445882Z 0 [Warning] [MY-000076] [Server] option
'transaction-read-only': boolean value 's' was not recognized. Set to OFF.

此命令会产生相同的警告,但也会产生一个错误,因此错误消息会与警告一起显示,退出码为 1:This command produces the same warnings, but also an error, so the error message is displayed along with the warnings and the exit code is 1:

$> mysqld --validate-config --log_error_verbosity=2
         --no-such-option --read-only=s --transaction_read_only=s
2018-11-05T15:43:53.152886Z 0 [Warning] [MY-000076] [Server] option
'read_only': boolean value 's' was not recognized. Set to OFF.
2018-11-05T15:43:53.152913Z 0 [Warning] [MY-000076] [Server] option
'transaction-read-only': boolean value 's' was not recognized. Set to OFF.
2018-11-05T15:43:53.164889Z 0 [ERROR] [MY-000068] [Server] unknown
option '--no-such-option'.
2018-11-05T15:43:53.165053Z 0 [ERROR] [MY-010119] [Server] Aborting

--validate-config 选项的范围仅限于服务器在不经过正常启动过程的情况下能够执行的配置检查。因此,配置检查不会初始化存储引擎和其他插件、组件等,也不会验证与那些未初始化子系统相关的选项。The scope of the --validate-config option is limited to configuration checking that the server can perform without undergoing its normal startup process. As such, the configuration check does not initialize storage engines and other plugins, components, and so forth, and does not validate options associated with those uninitialized subsystems.

--validate-config 可以随时使用,但在升级后尤其有用,用于检查升级后的服务器是否将以前与旧服务器一起使用的选项视为已弃用或过时。例如,tx_read_only 系统变量在 8.0 中被移除。假设一台 MySQL 5.7 服务器在其 my.cnf 文件中使用了该系统变量,然后升级到 MySQL 8.4。使用升级后的服务器运行 --validate-config 检查配置会产生以下结果:--validate-config can be used any time, but is particularly useful after an upgrade, to check whether any options previously used with the older server are considered by the upgraded server to be deprecated or obsolete. For example, the tx_read_only system variable was removed in 8.0. Suppose that a MySQL 5.7 server was run using that system variable in its my.cnf file and then upgraded to MySQL 8.4. Running the upgraded server with --validate-config to check the configuration produces this result:

$> mysqld --validate-config
2018-11-05T10:40:02.712141Z 0 [ERROR] [MY-000067] [Server] unknown variable
'tx_read_only=ON'.
2018-11-05T10:40:02.712178Z 0 [ERROR] [MY-010119] [Server] Aborting

--validate-config 可以与 --defaults-file 选项一起使用,以仅验证特定文件中的选项:--validate-config can be used with the --defaults-file option to validate only the options in a specific file:

$> mysqld --defaults-file=./my.cnf-test --validate-config
2018-11-05T10:40:02.712141Z 0 [ERROR] [MY-000067] [Server] unknown variable
'tx_read_only=ON'.
2018-11-05T10:40:02.712178Z 0 [ERROR] [MY-010119] [Server] Aborting

请记住,如果指定了 --defaults-file,它必须是命令行上的第一个选项。(如果反转选项顺序执行前面的示例,会产生一条消息,指出 --defaults-file 本身是未知的。)Remember that --defaults-file, if specified, must be the first option on the command line. (Executing the preceding example with the option order reversed produces a message that --defaults-file itself is unknown.)