Testing MySQL open_files_limit: Which Configuration Takes Effect – my.cnf, systemd Service, or Docker Limits
This article presents a systematic investigation of MySQL's open_files_limit setting across three scenarios—conflict between my.cnf and systemd service, effectiveness when using mysqld_safe, and the impact of Docker's own limits—revealing which source actually controls the maximum number of open files.
The author, a DBLE project test lead, conducts three positive‑test cases to determine which configuration governs MySQL's maximum open files limit.
Case 1: Conflict between my.cnf and mysqld.service
Both the MySQL configuration file ( open_files_limit = 65536 ) and the systemd service file ( LimitNOFILE = 65534 ) are set, then the service is reloaded and restarted. After checking /proc/ /limits , the limit is 65534, indicating the systemd service setting wins.
Case 2: Effect of my.cnf when MySQL is started via mysqld_safe
The MySQL documentation states that open_files_limit is applied when MySQL is launched by mysqld_safe . The author first verifies that the DMP platform starts MySQL directly (no mysqld_safe ), then restarts MySQL using mysqld_safe with --open-files-limit=65536 . The /proc/ /limits output shows 65536, confirming the configuration takes effect only with mysqld_safe .
Case 3: Absence of LimitNOFILE in the service file
After commenting out LimitNOFILE in the service file and restarting, the observed limit jumps to 1,048,576. Investigation of the cgroup hierarchy ( systemd-cgls ) shows the MySQL process inherits limits from the parent system.slice , which in turn inherits from Docker's own service ( docker.service ) where LimitNOFILE=1048576 is defined. Changing Docker's limit to 1,048,577 and restarting confirms the new value propagates to MySQL.
Conclusions :
When both my.cnf and systemd service specify a limit, the systemd service setting prevails.
The my.cnf open_files_limit is effective only when MySQL is launched via mysqld_safe .
If the service file does not define a limit, the effective limit is inherited from the nearest ancestor in the cgroup hierarchy, often Docker's own limit.
These findings highlight the importance of aligning MySQL configuration with the startup method and understanding the resource‑limit inheritance chain in containerized environments.
References: MySQL open_files_limit documentation Red Hat Resource Management Guide
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.