Skip to content

Checking your reading list…

Retry verification

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Why Adding foreign_key_checks to my.cnf Breaks MySQL Startup and How to Identify Non‑Configurable System Variables
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.

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.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

debuggingconfigurationMySQLforeign_key_checksNO_CMD_LINEsystem variables

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion