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)

10+ Year Member


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

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)

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

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)

WebmasterWorld Senior Member 5+ Year Member

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.

Featured Threads

Hot Threads This Week

Hot Threads This Month