Solve MySQL Too Many Connections Error On Redhat 7

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.

Solution 1:

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;

Check Out: How To Check Users In Mysql Database Server In Linux

Login to your MySQL server and run this command to check max_connection

show variables like "max_connections";

Solve MySQL Too Many

As you can see the default connection is 151 So you have to increase its size.

Check Out: Install MySQL 5.6 Database Server Using Repository

To change the value of max_connection can be done by the set command

SET GLOBAL max_connections =512;

mysql set max connections

Now verify.

too many connections mysql

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.

Check Out: Different Ways of Finding Table Size In Mysql Server

Now restart the MySQL service using systemctl restart mysqld or service mysqld start

Solution 2:

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.

Check Out: How To Install and Configure RDS Database On AWS Cloud

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
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

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment