The max_connections
system variable sets the maximum permitted number of simultaneous client connections.
If you are seeing "Too many connections" errors, increasing the max_connections
may help resolve the problem.
It is important to monitor server resource usage before and after adjusting max_connections
. Increasing the maximum
connections will result in higher memory usage.
The default value for this setting is 151 and the maximum is 100,000 (in MySQL 8.0). When adjusting this setting, try 2x the initial setting. The effective maximum connections will always be less than the open files limit (open_files_limit - 810).
You can use ServerPilot's MySQL monitoring dashboards
to know whether you need to increase the size of the max_connections
setting.
max_connections
settingCreate file:
/etc/mysql/conf.d/max_connections.cnf
with contents (e.g. to double the default of 151 to 300):
[mysqld] max_connections = 300
You can run the following command as "root" to create the configuration file shown above:
echo -e '[mysqld]\n''max_connections = 300' > /etc/mysql/conf.d/max_connections.cnf
Restart MySQL:
sudo service mysql restart
Check the new value of the variable with:
sudo mysql -e "SHOW VARIABLES LIKE 'max_connections';"