Databases 6 min read

Why Adding foreign_key_checks to my.cnf Breaks MySQL Startup and How to Identify Non‑Configurable System Variables

This article investigates why inserting the foreign_key_checks variable into MySQL's my.cnf causes the server to fail to start, explains the underlying NO_CMD_LINE flag mechanism, and provides a simple command‑line method to distinguish variables that can or cannot be set via configuration files.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Why Adding foreign_key_checks to my.cnf Breaks MySQL Startup and How to Identify Non‑Configurable System Variables

A colleague asked why adding the foreign_key_checks system variable to my.cnf prevented MySQL from starting. Although the variable exists in the official documentation and can be changed at runtime with SET, MySQL reports an unknown variable 'foreign_key_checks = 0' error during startup.

Reproducing the issue shows that MySQL aborts with the unknown‑variable error when the line foreign_key_checks = 0 is present in the configuration file. Further investigation revealed that the problem is not caused by the SESSION_VAR flag but by the NO_CMD_LINE flag attached to certain system variables.

Searching the source code for other variables marked with NO_CMD_LINE uncovered autocommit. When autocommit is placed in my.cnf without being added to the my_long_options array, MySQL also fails to start, confirming that variables with the NO_CMD_LINE flag cannot be read from the configuration file unless they are exposed through my_long_options or my_long_early_options.

The key insight is that a system variable defined in sql/sys_vars.cc and marked with NO_CMD_LINE is invisible to the configuration parser; adding it to my_long_options (or my_long_early_options) makes it configurable, as demonstrated with autocommit.

To quickly determine whether a variable can be set in my.cnf, run the MySQL server with the verbose help flag and grep for the variable name, e.g.:

/path/mysqld --verbose --help | grep "foreign-key-checks"

If there is no output, the variable cannot be configured via the file. Conversely, if the output contains a line such as --autocommit Set default value for autocommit (0 or 1), the variable is configurable.

In summary, encountering an unknown variable xxx error for a variable documented as supported indicates that the variable is not allowed in my.cnf. The same conclusion can be drawn from the absence of a corresponding --xxx entry in the verbose help output.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

debuggingConfigurationmysqlforeign_key_checksNO_CMD_LINEsystem variables
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.