Could not increase number of max_open_files to more than… (Solution)

A quick solution to the warning “Could not increase number of max_open_files to more than” when starting MySQL or MariaDB. For some background read How MySQL Opens and Closes Tables. Here’s an excerpt: “The table_open_cache and max_connections system variables affect the maximum number of files the server keeps open. If you increase one or both of these values, you may run up against a limit imposed by your operating system on the per-process number of open file descriptors. Many operating systems permit you to increase the open-files limit, although the method varies widely from system to system. Consult your operating system documentation to determine whether it is possible to increase the limit and how to do so.”

Also, read MySQL’s open_files_limit documentation,which stats: “The number of files that the operating system permits mysqld to open. The value of this variable at runtime is the real value permitted by the system and might be different from the value you specify at server startup. The value is 0 on systems where MySQL cannot change the number of open files. …The effective open_files_limit value is based on the value specified at system startup (if any) and the values of max_connections and table_open_cache. The server attempts to obtain the number of file descriptors using the maximum of those three values. If that many descriptors cannot be obtained, the server attempts to obtain as many as the system will permit.”

Too many open files

So for example if MySQL starts with the following warning:

Could not increase number of max_open_files to more than 65536

…this means the limit is being hit somewhere. Let’s resolve that by editing any configured limits. Have a look at the following files:

/etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
/etc/systemd/system/mysqld.service.d/limits.conf
/usr/lib/systemd/system/mariadb.service
/usr/lib/systemd/system/mariadb.service
/etc/systemd/system/mysql.service
/etc/systemd/system/mysqld.service

…the related MySQL or MariaDB files may be in other locations on non-RHEL systems.

Look within those files for the following config lines:

LimitNOFILE=
LimitMEMLOCK=

Change these lines to your new limit. For example:

LimitNOFILE=100000
LimitMEMLOCK=100000

Don’t use the infinity as value, defaults to 65536. (as reported here) So if you see the value infinity, replace it with your required limit. Once, you’ve done this, you should now reload system daemon and restart MySQL service:

systemctl daemon-reload
systemctl restart mysql

To check the new limit via mysql command line. You can use the follow query:

SHOW VARIABLES LIKE 'open_files_limit';

Make sure your new limit is set:

MariaDB [(none)]> SHOW VARIABLES LIKE 'open_files_limit';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| open_files_limit | 100000 |
+------------------+--------+

Tags: , , , , , ,