For the past days I’ve been getting the “Error establishing a database connection” message again on my Website (https://www.unidaystudio.com.br/) and trying to fix based on the answers here, google search and mainly this related DigitalOcean tutorial:


But I haven’t succedded in any of them.

I’ll explain the outputs I had following this tutorial and I think it will be helpful to understand what is going on. Also, I don’t know if that helps, but here is also a console output when I try to connect to the website:

Step 1 — Check the Server Memory Resources

sudo netstat -plt

Mysql Server is running:

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

Outputs nothing. Here is an extra htop screenshot of my server:
RAM Usage is 410M/986M.

Step 2 — Check Database Login Credentials

Checked and they’re correct: user, db name and password. Here is a screenshot:

Step 3 — Repairing the WordPress Database

I added the following code to wp-config.php:

define('WP_ALLOW_REPAIR', true);

Saved, uploaded and closed, then opened the .../wp-admin/maint/repair.php URL and got the exact same error:

Extra Steps I tried:

  • Disable all the plugins by renaming the /var/www/html/wp-content/plugins/ folder.
  • Reinstall mysql using apt-get
  • Restart mysql using: sudo service mysql stop; sudo service mysql start; and also using: systemctl restart mysql

So I’m basically out of ideas because every topic points to the same thing that I’ve already tried and failed.


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.

Submit an Answer
1 answer

To Fix “Error Establishing a Database Connection”
Step 1: Get In Touch With Your Web Host Provider.
Step 2: Check If Your Plugin or Theme Files Haven’t Been Corrupted.
Step 3: Check If Your Database Hasn’t Been Corrupted.
Step 4: Check Your Database Connection Credentials.
Step 5: Restore The Default WordPress Files.