Support » Fixing WordPress » Error establishing a database connection (Occurring Frequently)

  • Lately, my blog Success Stories (has a daily viewership of about 2500 people) has been showing “Error establishing a database connection” quite frequently. My wife had developed this theme from scratch without prior knowledge (she learnt web design in course of developing it)

    Earlier, I thought it was because of the “ordinary host-serving plan” so I got it upgraded to the premium one. But the problem remains unsloved. I contacted BlueHost and asked them if there was something they could do about it, to which they sent the following suggestion. Can anybody go through it as well as my blog and explain the solution in the simplest possible words?

    “I apologize for the trouble you’re experiencing.Our current limitation for concurrent MySQL connections is 15 per user; The error you’re receiving means your application is trying to establish more than 15 simultaneous MySQL connections with the same username at any given time, and the MySQL server is denying them.

    To fix this, you’ll need to prevent your program from making more than necessary connections; Unfortunately this can be a bit difficult to track since there’s no simple way to see what script/page is establishing the connection, but I can offer these suggestions; * Slowly performing queries may keep a script and connection open longer than necessary. Check your ~/tmp/mysql_slow_queries/ logs for entries on what queries are taking too long to finish. * Disable any plugins or extensions you may have; Some of these are poorly coded and will keep open MySQL connections or needlessly re-open connections, with no regards to server limitations. * Verify the program is up to date. * Try using FastCGI and Persistent MySQL Connections together. FastCGI is a separate way of handling PHP, that allows it to start a script and keep a script running for up to 5 minutes at a time, ergo allowing multiple requests per process to be served. This is enabled from cPanel > Software/Services > PHP Config > PHP5(FastCGI). Persistent MySQL connections cause your MySQL connections to stay open for the same query, allowing each connection to perform multiple queries, versus opening, querying, returning data, closing, ad infinitum. In conjunction these two modifications can help alleviate issues with connection problems. To enable Persistent MySQL connections, please consult the FAQ or user documents for your installed program.* Verify your program is not being spammed by bots. Forums, comment sections and data fields that input to a database can be compromised or exploited to cause issues like the ones you’re seeing. Check your ~/access-logs/ for logs about what is being accessed to check to see if there are any abusive patterns.* I recommend implementing a caching tool. Essentially caching is a tool or extension that takes requests from a certain interpreter (PHP, in your case) and stores a static copy of the whole or parts of a whole page; this allows Apache (web server) to serve subsequent requests, without having to redundantly query and obtain unchanged information, thereby reducing the number of MySQL connections it needs to return the same information. One we have seen great success with is xCache; this is non-supported, but does install properly in our environment–Myself and several other technicians here have done so, but please be aware it’s as-is, and we will not be able to provide any installation help with it. In any case, it can be obtained from here:

    There are some basic installation directions relevant to our environment here: If you want to do it per-script, investigate the use of a “Caching” style plugin. Scripts like Joomla have this built into the administrator section, and WordPress has a great plugin for this available here;

    In addition to this, I recommend doing a MySQL repair and optimize on your databases, and consult your web developer for further assistance.
    Our current limitation for concurrent MySQL connections is 15 per user; The error you’re receiving means your application is trying to establish more than 15 simultaneous MySQL connections with the same username at any given time, and the MySQL server is denying them.

    I will appreciate your help.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Josh


    Moderator and Editor Customizer

    Well… it sounds like you have way too many (or poorly developed) plugins. As he said, there are some plugin developers who may not have proper MySql knowledge, and may leave connections open, or open a new connection when one is already open.

    I doubt this is a WP bug. I would be almost certain it’s a plugin issue.

    Are you able to replicate this error “on demand”? If so, try deactivating a few of your plugins at a time, and then attempting to re-generate the error.

    Once you find the plugin which is causing all these connections… you can either contact the author, or seek an alternative.

    I have been using the following plugins for several months now:

    1. AddThis Social Bookmarking Widget.
    2. Disqus Comment System
    3. Facebook Fan Box
    4. Facebook Like Button Plugin
    5. Facebook Like Thumbnail
    6. Facebook Page Promoter Lightbox
    7. Google XML Sitemap for Images
    8. Google XML Sitemaps
    9. Secure WordPress
    10. Twitter for WordPress
    11. User Photo
    12. W3 Total Cache
    13. WordPress SEO
    14. WP-Affiliate
    15. WP-PageNavi
    16. WP
    17. WP Tweet Button



    Moderator and Editor Customizer

    Well, I don’t use any of those plugins… so I’m unfamiliar with them all.

    But, I would do it in groups… (all facebook plugins), and then check and see if the error persists… (all WP plugins), see if error persists… etc.

    Thanks Josh!
    Going to do as suggested.



    Moderator and Editor Customizer

    Good. I know it’s a PAIN!! But, I would almost bet money it’s a plugin causing your issues. It’s just the painful task of finding which one.

    Moderator kmessinger


    You also have markup errors and the W3 Total Cache is not being used for CDN either,

    Thanks Josh!

    I deleted two plugins and the frequency of the error has gone down to a dramatic level. The problem is it still exists. I need to carefully test it (say deactivating two or three plugin a day and see how it works)

    By the way, I have seen CDN to be unchecked. The problem is I have no idea what to put in the value box.
    If you have done this before, please let me know.


    Nothing worked and finally I changed my DNS server to CloudFlare and now it is opening.

    There is one thing I’d like to raise to this forum…Are BlueHost responsible for the errors?
    The Blog was mentioned in BBC Magazine and naturally that increased the traffic volume for two-three days. The hosting account is Premium and they say everything is unlimited.

    What’s your say?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Error establishing a database connection (Occurring Frequently)’ is closed to new replies.