homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Mysql too many connections
One long mysql connect better than a number of short ones?

5+ Year Member

Msg#: 4436986 posted 8:36 am on Apr 4, 2012 (gmt 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




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

Msg#: 4436986 posted 11:27 am on Apr 4, 2012 (gmt 0)

mod_dbd - Apache HTTP Server:
http://httpd.apache.org/docs/2.2/mod/mod_dbd.html [httpd.apache.org]


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

Msg#: 4436986 posted 1:01 pm on Apr 4, 2012 (gmt 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. :)


WebmasterWorld Senior Member 5+ Year Member

Msg#: 4436986 posted 11:41 am on Apr 5, 2012 (gmt 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved