How to Resolve MySQL Error 1040 (HY000): Too many connections

Error 1040 (HY000): Too many connections

Recently, I saw some blank pages on my website without any error, especially when the web server was very busy. I suspected that somewhere in PHP codes caught the exception and threw nothing. So I decided to display the error on the screen:

SQLSTATE[HY000] [1040] Too many connections

It looked like a resource limitation of mysql was reached, so I first checked the current value of it.

mysql> show variables like 'max_connections';
| Variable_name   | Value |
| max_connections | 151   |
1 row in set (0.00 sec)

It’s the default value. So I decided to lift the connection limit of mysqld like this:

[root@test ~]# vi /etc/my.cnf

After that, you should restart mysqld to make it effective.

[root@test ~]# systemctl restart mysqld

Please periodically check how many connections that is created during the busy hours of server.

mysql> show processlist;

Then you will know how many connections that you really need.

Leave a Reply

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