Question

Error establishing a database connection

Posted November 13, 2020 110 views
WordPress

I have hosted a website on DigitalOcean.
I deleted unused media through a plugin “Media cleaner” (approximately 2K images).
But it deleted some used images.
Before doing this I have made a backup of only uploads through the Updraftplus plugin.
So I restored the backup.
Reassigned shortcodes in oxygen.
But something happened and now it is showing “Error establishing a database connection”
How to solve this? It’s urgent. Thank You!

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.

×
1 answer

Hello,

The “Error establishing a database connection” occurs when WordPress is unable to make a connection to the database. A number of things can affect your WordPress database connection.

This issue can be caused by incorrect database information in your WordPress settings, corrupt database, or an irresponsive database server. You can refer to our community article for more information

https://www.digitalocean.com/community/tutorials/how-to-debug-the-wordpress-error-establishing-database-connection

One of the most common reason is MySQL stopped running. It stopped or failed to start as a result of not enough memory.

A useful program to review the logs one page at a time is less, for example:

less /var/log/mysql/error.log

If you see memory issues such as mmap can’t allocate then you can be sure that you are having memory issues. You can choose to optimize your MySQL configuration, or use caching mechanisms to reduce the application’s load on MySQL. If nothing works, you can try resizing your server to a one with higher CPU and RAM.

Hope this helps!

Cheers,
Lalitha

by Brian Boucheron
WordPress is one of the most popular open source content management systems in the world. Although it started out focused on blogging, over the years it has developed into a more flexible platform for websites in general. After almost fifteen years of development it is quite polished and robust, yet issues can still come up. If you've recently attempted to load your WordPress-powered website and instead saw a message stating "Error Establishing Database Connection", the cause is most often...
  • Thank you. The issue is solved. I followed the same guide you mentioned.
    Now whenever I try to use the media library I am getting “Error establishing a database connection” then when I restart database site is up.

Submit an Answer