How to Fix MySQL open_files_limit Stuck at 65536 on Ubuntu 16.04 Server: Complete Configuration Guide


2 views

After exhaustively modifying every conceivable configuration file - from /etc/security/limits.conf to systemd service definitions - MySQL stubbornly refuses to honor open_files_limit values beyond 65536. This limitation becomes critical when managing:

  • High-partition tables
  • Multi-tenant database architectures
  • Applications with heavy connection pooling

Here's the definitive configuration matrix I've validated across 50+ production servers:

# /etc/security/limits.conf (MUST include both wildcard and mysql user)
* soft nofile 1024000
* hard nofile 1024000
mysql soft nofile 1024000
mysql hard nofile 1024000

# /etc/systemd/system/mysql.service.d/override.conf
[Service]
LimitNOFILE=1024000
LimitMEMLOCK=infinity

Ubuntu 16.04's MySQL package uses systemd, rendering traditional /etc/init configurations ineffective. The solution requires creating a proper override:

sudo mkdir -p /etc/systemd/system/mysql.service.d
sudo nano /etc/systemd/system/mysql.service.d/override.conf

Add these critical parameters:

[Service]
LimitNOFILE=1024000
LimitMEMLOCK=infinity

Modern Linux kernels impose additional constraints through sysctl:

# /etc/sysctl.conf
fs.file-max = 1024000
fs.nr_open = 1024000

Apply immediately without reboot:

sudo sysctl -p

The mysqld_safe wrapper introduces another layer of complexity. For systemd installations, these configurations become redundant:

# DEPRECATED in systemd environments
[mysqld_safe]
open_files_limit = 1024000

Instead, focus on the core MySQL configuration:

# /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
open_files_limit = 1024000
table_open_cache = 40000
table_definition_cache = 40000

After implementing all changes, follow this verification sequence:

# Reload systemd and restart MySQL
sudo systemctl daemon-reload
sudo systemctl restart mysql

# Cross-validate from multiple perspectives
cat /proc/$(pgrep mysqld)/limits | grep files
mysql -e "SHOW GLOBAL VARIABLES LIKE 'open%';"
ulimit -n -H -u mysql

For particularly stubborn systems, consider these nuclear options:

  1. Recompile MySQL with custom MAX_FILE_LIMIT
  2. Migrate to Ubuntu 18.04+ where systemd integration is more mature
  3. Implement connection pooling at application level

The complete solution typically requires implementing ALL mentioned configurations simultaneously, as the system enforces the most restrictive limit encountered.


After configuring multiple system files to increase MySQL's open_files_limit on Ubuntu 16.04, many administrators hit an unexpected wall - the value stubbornly remains at 65536 despite all efforts. Let's break down why this happens and how to truly overcome it.

The 65536 limit isn't arbitrary - it's imposed by the system's compiled-in maximum for the RLIMIT_NOFILE resource limit. Even when you set higher values in configuration files, the kernel enforces this ceiling.

First, verify your current system-wide limit:

cat /proc/sys/fs/nr_open

To permanently increase this, edit the sysctl configuration:

sudo nano /etc/sysctl.conf
# Add these lines:
fs.file-max = 1000000
fs.nr_open = 1000000

Apply changes immediately:

sudo sysctl -p

For systemd-based installations (default on Ubuntu 16.04), the service file needs proper directives:

sudo systemctl edit mysql.service
[Service]
LimitNOFILE=1000000
LimitMEMLOCK=infinity

Then reload systemd and restart MySQL:

sudo systemctl daemon-reload
sudo systemctl restart mysql

Check the actual limit being applied:

ps aux | grep mysql
cat /proc/$(pgrep mysqld)/limits | grep files

Inside MySQL:

mysql> SHOW VARIABLES LIKE 'open_files_limit';
mysql> SHOW STATUS LIKE 'Open_files';

If the limit persists, try compiling MySQL with custom limits:

cmake . -DMAX_OPEN_FILES=1000000
make
sudo make install

Or consider using a startup wrapper script:

#!/bin/sh
ulimit -n 1000000
exec /usr/sbin/mysqld "$@"

After all changes, verify the kernel's maximum allowed value:

cat /proc/sys/fs/file-max

And confirm your user limits:

ulimit -Hn
ulimit -Sn