Databases 6 min read

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

This article investigates why inserting the foreign_key_checks system variable into MySQL's my.cnf prevents the server from starting, 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 Causes MySQL Startup Failure and How to Identify Non‑Configurable System Variables

A colleague asked why adding foreign_key_checks to my.cnf makes MySQL fail to start. Although the variable exists in the official documentation and can be changed with SET, MySQL reports an unknown variable error when it appears in the configuration file.

The investigation reveals that some system variables are marked with the NO_CMD_LINE flag, which prevents them from being recognized in the configuration file. By examining MySQL source code (version 8.0.32), the author discovers that variables like foreign_key_checks and autocommit have different definitions across sql/sys_vars.cc and sql/mysqld.cc.

Through a series of experiments—adding autocommit to the config, removing it from my_long_options, and creating a custom variable with the NO_CMD_LINE flag—the author confirms that variables defined with NO_CMD_LINE in sql/sys_vars.cc cannot be parsed during startup unless they are also listed in my_long_options or my_long_early_options.

To quickly determine whether a variable can be set in my.cnf, the following command can be used: /path/mysqld --verbose --help | grep "xxx" If the output contains a line like --xxx with a description, the variable is configurable via the configuration file; otherwise, it is not.

For example, running the command for foreign_key_checks yields no output, indicating it cannot be set in my.cnf. Conversely, running it for autocommit shows a description, confirming it is configurable.

Note: When using grep , replace underscores in variable names with hyphens (e.g., foreign-key-checks ).

In summary, encountering an unknown variable xxx error during MySQL startup means the variable is not supported in the configuration file, and the --verbose --help method provides a reliable way to verify configurability.

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.