I have created website on my server, and i have bought hosting from a company and then I updated the DNS IP, after that when i try to open this website it opened fine but sometimes it gives me this error

Error establishing a database connection

Not every time, Can anyone tell me why this is happening that it opens sometimes and sometimes it shows me the error ?

1 Answer 1


A database error can occur for many reasons. It's usually the result of an incorrect database address, username, or password. It's likely not a timeout failure, since WordPress has a separate error for that. Here are two common issues:

DB Configuration

Since you have intermittent failures, this likely points to an issue with the database server itself. If you are on a shared host, it's possible they have overloaded their servers. Your best option is to contact your host's technical support and have them verify the mySQL load and move you to a different server if needed.

Without know more details about your server configuration it's hard to diagnose further.

Cache Configuration

It might also be an issue with a caching plugin, do you have one?

You could have cache miss. This occurs when something is looked up in the cache and is not found. In this scenario, WordPress then has to generate the content from the database and save it to cache. When configured correctly, a cache miss should not produce an error.

Without know more details about your plugins it's hard to diagnose further.


It's possible that your site has been compromised. You should compare your wp-config.php file to wp-config-sample.php. Only the values of the existing named constants should be different. There should be no additional code or defined values.

  • Thanks for your detailed answer. optiion 1: I have site hosted on VPS server and it's not shared. option2: i have chache plugin but plugin is disabled already. option3: wp-config is configured properly, i have doubled check it. Jan 23, 2017 at 10:23
  • What web server and DB server are you using? Can you post any error logs from your web server?
    – fergbrain
    Jan 23, 2017 at 10:28
  • it is a vps server from digital ocean, i have installed xampp there and configured the website. After that, I asked my hosting company to chnage DNS ip from there to my server IP. so basically site is running from my server now Jan 23, 2017 at 10:39
  • I've you've not configured or maintained a VPS before, you may want to use a droplet preconfigured for WordPress: digitalocean.com/community/tutorials/…
    – fergbrain
    Jan 23, 2017 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.