Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Mysql too many connections

One long mysql connect better than a number of short ones?

8:36 am on Apr 4, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:May 7, 2005
posts: 143
votes: 0


I've got a big problem on my websites at the moment.

At peak times I get too many connection errors on my websites which prevents some people from viewing.

- Dedicated server
- Optimized tables with indexes
- non-persistent connections.

What I do is make the mysql connect at the start of each page, run the queries and let the page auto disconnect at the end of each script.

Would it be better to do numerous connect and close after each query?

Any other ideas how I can beat this crippling problem?

Thank you

11:27 am on Apr 4, 2012 (gmt 0)


WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
votes: 94

mod_dbd - Apache HTTP Server:
http://httpd.apache.org/docs/2.2/mod/mod_dbd.html [httpd.apache.org]
1:01 pm on Apr 4, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
votes: 0

A good place to start debugging this is MySQL's "too many connections" page [dev.mysql.com].

Typically, most modern web servers can support many more than 150 connections. In fact, most web servers are still using default settings that were designed for hardware from 3 - 10 years ago. A little bit of tuning can go a long way towards avoiding problems.

If you've already tuned the settings and you're still getting this problem, then, well, it could just be that you have a very popular site and need to upgrade your hardware. :)
11:41 am on Apr 5, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 30, 2007
votes: 0

You may want to reduce the wait_timeout variable so mysql processes don't wait too long. You should setup the log_slow_queries in the mysqld section of my.cnf so you can record queries that take too long eg:

# close the connection after 15secs inactivity

# record queries which take longer than 3 secs.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members