Recently, my VPS which hosted a bunch of WordPress sites gave an error message: Too many connections. I mean all available connections have been used by the various clients and my MySQL server can not serve any new connections until any of the existing connections is closed.
How Many Connections Can MySQL handle?
The default, MariaDB 10.3.34 can handle up to 151 connections. The number is stored in a server variable called max_connections.
How to Increase Max Connection in MySQL?
Check the default max connections
The main command is:
show variables like "max_connections";
The output is 151.
Increase Max Connections in settings
The file keeps the setting of max_connections is located /etc/mysql/mariadb.conf.d/ the file name is 50-server.cnf
cd /etc/mysql/mariadb.conf.d sudo nano 50-server.cnf
Find the line of max_connections , remove the comment characters or just just add the following in to the end of the file, save it.
max_connections = 200
Restart MySQL server
sudo service mariadb restart
Then, try to check the max connections variable by the previous way mentioned above, the result is 200.