20. August 2010 · 9 comments · Categories: Linux
"Unable to connect to database: Too many connections" - common issue ...

Cause:
This error means that the limit of simultaneous MySQL connection to mysql server is
reached and new connections to the server cannot be established at this time.

Resolution:
There are two ways to solve this issue. The first one is increase the connection
limit and the second, find what is the reason of “too many connection” error and
try to lower MySQL server usage.

MySQL server state can be checked using ‘mysqladmin’ utility. For example to find out
the number of current connections to the server use:

#mysqladmin -uadmin -p extended-status | grep Max_used_connections
| Max_used_connections | 11 |

Current connections limit settings can be found with:

#mysqladmin -uadmin -p variables | grep 'max.*connections'
| max_connections | 100 |
| max_user_connections | 0

In the example above, maximum number of connections to the server (max_connections)
is set to 100. And maximum number of connections per user (max_user_connections)
to zero, that means unlimited.
There are default MySQL values. They can be redefined in /etc/my.cnf, for example:

[mysqld]
set-variable=max_connections=150
set-variable=max_user_connections=20

Restart MySQL after my.cnf is modified.

Note, if you set connections limit to very high value (more than 300) it may
affect the server performance. It is better to find out the reason of the high
MySQL server usage.
You may check what users/requests slow mysql and take all curent connections,
for example with the command:

# mysqladmin -uadmin -p processlist

9 Comments

  1. I truly loved this brilliant article. Please continue this awesome work. Regards, Duyq.

  2. Pingback: Tibia

  3. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

  4. I can’t but agree.I always wanted to write in my site something like that but I guess you’r faster.

  5. Usually I do not post on blogs, but I would like to say that this article really forced me to do so! Thanks, really nice article.

  6. Gday, I was checking this webpage with my phone and this appears somewhat strange. Decided you’d would like to know. It’s a good post however, just didn’t mess that up.

  7. Heya blog owner, I have a simple request. I was just googleing for some info on this topic you wrote and found this blog. Some really nice stuff you got here, can I please link to this post on my new website I am working on? Please :). I will check back again later to see what you answered. cheers, Criss Miller .

  8. Hi. I genuinely liked reading through your current article!. High-quality material. I would undoubtedly recommend you to come up with articles a bit more frequently. By doing this, having this kind of a helpful blog I feel you will rank higher in the search engines . I also subscribed to your Rss. Continue the good job!

  9. @Denis Lopez : Yes you can.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

css.php