Question

Site shows "Error establishing a database connection"

My WordPress site had been fine all along, but roughly 36 hours ago, I noticed that it doesn’t load the site but shows Error establishing a database connection instead.

I certainly have not made any changes to the WordPress site itself, or my droplet settings recently.

What might have caused this? Thanks for any advise!

Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Jonathan Tittle
DigitalOcean Employee
DigitalOcean Employee badge
June 10, 2019
Accepted Answer

@arunsathiya

If the error was at random, I would recommend checking the MySQL error log to see if there was a crash. The command below will output the last 50 lines from the MySQL error log.

tail -50 /var/log/mysql/error.log

If you see lines with Out of memory or Killed process, MySQL is unable to allocate the RAM it needs to continue to run and the OOM killer is killing off the process.

There are a few ways to resolve this

  • Reboot the Droplet (short-term solution to get you back online)
  • Resize your Droplet
  • Optimize the MySQL configuration (MySQL Tuner is a great tool to get you started)
  • Enable Caching for your WordPress using a plugin (W3 Total Cache works very well)

Caching can help reduce resource usage by caching commonly requested data which, in turn, reduces the number of database calls that need to be made. It can be highly effective when combined with MySQL Tuner and general optimization.

Resizing is really the final recommendation when you’ve reached the point where you’ve enabled caching, optimized your configuration the best you can, and you still can’t get the resource usage under control (i.e. you just need more RAM).

Bobby Iliev
Site Moderator
Site Moderator badge
June 10, 2019

Maybe there was a locked table and you reached your MySQL max connections limit or the droplet ran out of memory and MySQL got killed. Were you able to check if MySQL was running and could you check your connections?

This comment has been deleted

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Become a contributor for community

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    DigitalOcean Documentation

    Full documentation for every DigitalOcean product.

    Resources for startups and SMBs

    The Wave has everything you need to know about building a business, from raising funding to marketing your product.

    Get our newsletter

    Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

    New accounts only. By submitting your email you agree to our Privacy Policy

    The developer cloud

    Scale up as you grow — whether you're running one virtual machine or ten thousand.

    Get started for free

    Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

    *This promotional offer applies to new accounts only.