As of MySQL 8.0.16, MySQL Server supports a 从MySQL 8.0.16开始,MySQL Server支持--validate-config
option that enables the startup configuration to be checked for problems without running the server in normal operational mode:--validate-config
选项,该选项允许检查启动配置是否存在问题,而无需在正常操作模式下运行服务器:
mysqld --validate-config
If no errors are found, the server terminates with an exit code of 0. 如果没有发现错误,服务器将终止,退出代码为0。If an error is found, the server displays a diagnostic message and terminates with an exit code of 1. 如果发现错误,服务器将显示诊断消息并以退出代码1终止。For example:例如:
shell> 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
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
再次运行服务器。
For the preceding example, where use of 对于前面的示例,如果使用--validate-config
results in display of an error message, the server exit code is 1. --validate-config
会显示错误消息,则服务器退出代码为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. log_error_verbosity
值,还可能显示警告和信息消息,但不会立即终止验证或退出代码为1。For example, this command produces multiple warnings, both of which are displayed. But no error occurs, so the exit code is 0:例如,此命令会生成多个警告,两个警告都会显示。但没有发生错误,因此退出代码为0:
shell>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.
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:此命令会产生相同的警告,但也会产生错误,因此错误消息将与警告一起显示,退出代码为1:
shell>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
The scope of the --validate-config
option is limited to configuration checking that the server can perform without undergoing its normal startup process. --validate-config
选项的作用域仅限于服务器在不经历正常启动过程的情况下可以执行的配置检查。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
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. --validate-config
可以随时使用,但在升级后特别有用,可以检查升级后的服务器是否认为以前用于旧服务器的任何选项已被弃用或过时。For example, the 例如,在MySQL5.7中,tx_read_only
system variable was deprecated in MySQL 5.7 and removed in 8.0. tx_read_only
系统变量被弃用,在8.0中被删除。Suppose that a MySQL 5.7 server was run using that system variable in its 假设MySQL5.7服务器在my.cnf
file and then upgraded to MySQL 8.0. my.cnf
文件中使用该系统变量运行,然后升级到MySQL 8.0。Running the upgraded server with 使用--validate-config
to check the configuration produces this result:--validate-config
运行升级的服务器以检查配置会产生以下结果:
shell> 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
can be used with the --defaults-file
option to validate only the options in a specific file:--validate-config
可与--defaults-file
选项一起使用,以仅验证特定文件中的选项:
shell> 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
Remember that 请记住--defaults-file
, if specified, must be the first option on the command line. --defaults-file
(如果指定)必须是命令行上的第一个选项。(Executing the preceding example with the option order reversed produces a message that (使用反转的选项顺序执行前面的示例会生成一条消息,即--defaults-file
itself is unknown.)--defaults-file
本身未知。)