For “Too Many Connections” Error in MySQL

Some times on your server in MySQL there is too many connections issue occurs. To resolve this issue you need to increase the value of max_connections. In this article we will help you how to update max_connections in MySQL.

many connections

See Also:
1. Mysql Commands for CentOS/RHEL
2. How to Resize MySQL InnoDB logs file in CentOS/RHEL
3. Install LAMP (Apache 2.4, MySQL 5.6, and PHP 7.0) on Ubuntu using PPA
4. Install LAMP (Apache 2.4, MySQL 5.6, and PHP 7.0) on CentOS/RHEL 7
5. How to configure Master-Slave MySQL Replication on CentOS/RHEL 5/6/7

Check max_connections Value:

To check the value of max_connections you need to login on mysql terminal with root privileged user.

# mysql -u root -p
mysql> SHOW VARIABLES LIKE "max_connections";
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 200   |
+-----------------+-------+
1 row in set (0.00 sec)

Update max_connections Value:

We can update the max_connections value as below:

Temporary Changes:
Before changing the value, make sure you server have enough resources to handle more connections. Run the below command from mysql terminal with root privileged user.

mysql> SET GLOBAL max_connections = 400;

After restarting MySQL service value will be reset.

Permanent Changes:
To set value permanently you need to add variable in mysql configuration file on your server. By default mysql configuration file is /etc/my.cnf but on some server mysql configuration file is /etc/mysql/my.cnf.

# vim /etc/my.cnf
Or
# vim /etc/mysql/my.cnf
max_connections = 400

After adding the variable in MySQL configuration file restart MySQL service to reflect the changes.

# service mysqld restart

Enjoy it!

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.