Question

Error establishing a database connection

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!


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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello, @sushpawar2500

Have you checked the MySQL error_log in order to see if the server is running out of memory or if the issue is with to many MySQL connections? As per the tutorial you can run this command in order to check if the server have recently run out of memory:

zgrep -a "allocate memory" /var/log/mysql/error.log*

zgrep will search through log files, including older log files that have been archived as compressed .tar.gz files. We’re searching for lines that contain allocate memory, in any error.log* file in the /var/log/mysql/ directory.

You can always login and check the MySQL error_log when the issue occurs using tail to either check the last 100 entries in the log or monitor the log in real time:

tail -n 100 /var/log/mysql/error.log

and monitor it in real time:

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

Hope that this helps! Regards, Alex

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