为何MariaDB中mysqld_safe生效open_files_limit而mysqld不生效?
open_files_limit Isn't Working for mysqld (But Works for mysqld_safe) Hey there, let's dig into why your open_files_limit setting isn't taking effect on the mysqld process—this is a common gotcha with MySQL/MariaDB configs. Here's the breakdown:
1. You Used the Wrong Configuration Section
The [mysql] block in my.cnf is designed for the MySQL client tool (the interactive mysql command you use to connect to the server), not the mysqld database daemon itself. That's why the setting only affected mysqld_safe (and likely by accident, not intentional) but ignored the actual server process.
To fix this, move your open_files_limit = 32000 line to one of these sections instead:
[mysqld]: This directly targets the database server process, so the limit will apply tomysqlddirectly.[mysqld_safe]: Sincemysqld_safeis the wrapper script that launchesmysqld, setting it here will pass the limit to the childmysqldprocess (useful for older distributions or systems where directmysqldconfig is restricted).
2. System-Level Limits Might Be Blocking Your Setting
Even if you fix the config section, system-enforced limits could override your MariaDB setting. Check these two key spots:
/etc/security/limits.conf: Ensure themysqluser has permission to open enough files. Add these lines if they're missing:mysql soft nofile 32000 mysql hard nofile 32000- Systemd Service Limits (if using systemd): If MariaDB is managed by systemd, the service file may restrict open files. Edit the service file (usually
/etc/systemd/system/mariadb.serviceor/usr/lib/systemd/system/mariadb.service) and add this under the[Service]block:
Then runLimitNOFILE=32000systemctl daemon-reloadand restart MariaDB to apply the change.
3. Verify the Fix
After making these adjustments, restart MariaDB:
systemctl restart mariadb # Or `service mariadb restart` for non-systemd systems
Then check the mysqld process limits again:
cat /proc/$(pgrep mysqld)/limits | grep "Max open"
You should now see the limit set to 32000.
内容的提问来源于stack exchange,提问作者Samuel Mutel

