Skip to content
/ server Public

MDEV-31527: Add --validate-config option to check configuration without starting the server#4716

Open
bodyhedia44 wants to merge 1 commit intoMariaDB:mainfrom
bodyhedia44:MDEV-31527-validate-config
Open

MDEV-31527: Add --validate-config option to check configuration without starting the server#4716
bodyhedia44 wants to merge 1 commit intoMariaDB:mainfrom
bodyhedia44:MDEV-31527-validate-config

Conversation

@bodyhedia44
Copy link

@bodyhedia44 bodyhedia44 commented Mar 1, 2026

MDEV-31527: Add --validate-config option

Summary

Add a new --validate-config command-line option that validates the server
configuration (from config files and command line) and exits with exit code
0 on success or non-zero on failure, without actually starting the server.

Use case

mariadbd --defaults-file=/etc/my.cnf --validate-config

DBAs can verify configuration changes before restarting production servers.

Test cases (mysql-test/main/validate_config.test):

  1. Valid config → exit 0
  2. Unknown CLI option → exit non-zero
  3. No pid file created (server doesn't start)
  4. No help text output
  5. Bad option in config file → exit non-zero with error message
  6. Valid config file → exit 0 with success message

Exit codes

Scenario Exit code
Valid configuration 0
Unknown option 2
Unknown variable 7

How to use

Validate a config file before restarting

mariadbd --defaults-file=/etc/my.cnf --validate-config

Validate with additional command-line overrides

mariadbd --defaults-file=/etc/my.cnf --validate-config --max-connections=500

Matching MySQL 8.0 behavior

This is equivalent to MySQL 8.0's --validate-config option, adapted for
MariaDB's parsing architecture.

@bodyhedia44 bodyhedia44 force-pushed the MDEV-31527-validate-config branch from 6aa192c to 82f19f2 Compare March 1, 2026 23:27
…ut starting the server

Add a new --validate-config command-line option that validates the server
configuration (from config files and command line) and exits with 0 on
success or non-zero on failure, without actually starting the server.

This is useful for DBAs to verify configuration changes before restarting:
  mariadbd --defaults-file=/etc/my.cnf --validate-config

The implementation reuses the existing --help code path (opt_abort),
which already loads plugins to validate their variables and runs a
final parsing pass with skip_unknown=0 to detect unknown options.
The only difference is that --validate-config suppresses help output.

Changes:
- Added my_bool opt_validate_config global variable
- Added --validate-config entry in my_long_options[]
- In get_options(): set opt_abort=1
Add a new --validate-config command-line option that validates the server
configuration (from config files and command line) and exits with 0 on
success or non-zero on failure, without actually starting the server.

This is useful for DBAs to verifql-configuration (with 6 scenarios including config file
  validation
@bodyhedia44 bodyhedia44 force-pushed the MDEV-31527-validate-config branch from 82f19f2 to 99d166e Compare March 2, 2026 00:17
@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 2, 2026
Copy link
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. This is a preliminary review.

@@ -4131,7 +4134,7 @@ static int init_common_variables()
sf_leaking_memory= 0; // no memory leaks from now on

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the else if() from above be a regular if() { sql_print_information() } here.

--echo #
--echo # Test 1: --validate-config with valid configuration should succeed (exit 0)
--echo #
--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/validate_config --skip-grant-tables --validate-config >$MYSQLTEST_VARDIR/tmp/validate_config/test1.log 2>&1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need --skip-grant-tables and --skip-networking? It's not supposed to matter.

--exec $MYSQLD_BOOTSTRAP_CMD --skip-networking --datadir=$MYSQLTEST_VARDIR/tmp/validate_config --skip-grant-tables --validate-config >$MYSQLTEST_VARDIR/tmp/validate_config/test5.log 2>&1
# The log should NOT contain the --help option listing
--let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/validate_config/test5.log
--let SEARCH_PATTERN=To see what values a running
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd find a better, more stable text to search.
Note that on my computer, this is never produced. I get:

blackbook:~$dev/server-main/bld/sql/mariadbd --help
dev/server-main/bld/sql/mariadbd  Ver 13.0.0-MariaDB-debug for osx10.21 on arm64 (Source distribution)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Starts the MariaDB database server.

Usage: dev/server-main/bld/sql/mariadbd [OPTIONS]

For more help options (several pages), use mariadbd --verbose --help.
blackbook:~$

I'd suggest using either "^Usage:.*mariadbd" or "Starts the MariaDB database server.".

--let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/validate_config/test6.log
--let SEARCH_PATTERN=unknown variable 'zzz_bogus_option=123'
--source include/search_pattern_in_file.inc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not remove the file right here? Makes for a better test locality.
Optional: I've got into the habit of prefixing all the temp files produced by tests with the "mdev-" so that, if something is left on disk by error, the name is more distinct.

# mysqld refuses to run as root normally.
--source include/not_as_root.inc

mkdir $MYSQLTEST_VARDIR/tmp/validate_config;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need a specific tmp subdir with your files? Why not just use the base tmp but prefix the files with the mdev number as suggested below?

[mariadb]
max_connections=50
EOF
--exec $MYSQLD --defaults-file=$MYSQLTEST_VARDIR/tmp/validate_config/good.cnf --skip-networking --skip-grant-tables --validate-config --lc-messages-dir=$MYSQL_SHAREDIR --datadir=$MYSQLTEST_VARDIR/tmp/validate_config --plugin-dir=$MYSQLTEST_VARDIR/plugins --character-sets-dir=$MYSQL_CHARSETSDIR --console --core-file >$MYSQLTEST_VARDIR/tmp/validate_config/test7.log 2>&1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of options you do not need here too.

--let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/validate_config/test7.log
--let SEARCH_PATTERN=Configuration is valid
--source include/search_pattern_in_file.inc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test (and describe in the MDEV what is the expected behavior) for the new option with --verbose, with --help and --bootstrap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

2 participants