Increase the MySQL max connections
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.
In MySQL 8.0, the default value is 151 and the maximum is 100,000.
You can use ServerPilot’s
MySQL monitoring dashboards
to know whether you need
to increase the value of max_connections
.
Change the MySQL max_connections
setting
Create the file:
/etc/mysql/conf.d/max_connections.cnf
with the following contents (replace VALUE with the desired size).
[mysqld]max_connections = VALUE
For example, the following sets the maximum connections to 300.
[mysqld]max_connections = 300
After creating the file, restart MySQL.
sudo service mysql restart
Confirm the new value with the following command:
sudo mysql -e "SHOW VARIABLES LIKE 'max_connections';"