It can be as when a client tries to connect MySQL server then request if it’s rejected or not connected and received an error “Mysql too many connections“ to the server has been reached. we can also set max connections in MySQL.
You get these errors when a number of connections exceeded the limits on the server. So you will have to increase max_connections request in my.cnf file in order to resolve this issue.
Solve MySQL too many Connections Error:
you can also use the below command to find the connections on MySQL server.
mysql -u root -p -se “select @@max_connections”;
We can also set the failed connection in MySQL error logs using SET GLOBAL log_warnings = 2;
Login to your MySQL server and run this command to check max_connection
show variables like "max_connections";
As you can see the default connection is 151 So you have to increase its size.
To change the value of max_connection can be done by the set command
SET GLOBAL max_connections =512;
This’s a temporary solution as when MySQL service would be restart, this would again set to default value 151. To make it permanent, change it in /etc/my.cnf file.
Now restart the MySQL service using systemctl restart mysqld or service mysqld start
Set Max Open Files Value MySQL:
Once you check the MySQL error log and you find an error related to maximum open files. So, we also need to increase max_open_files.
Locate the systems folder for MySQL and create a file override.conf and put the below parameter in this file.
vim /etc/systemd/system/mysql.service.d/override.conf [Service] LimitNOFile= 10000 TasksMax= 10000 LimitNPROC= 10000
Run the below commands.
systemctl daemon-reload systemctl restart mysqld
The connections values depend on the application load and we don’t have a fixed value to set. you can always make changes to increase the connection on the server.
That’s it. mysql set max connections