Broken connection between WordPress and Database.
Photo by Yuriy Vertikov on Unsplash

Solved: “Error Establishing a Database Connection” in WordPress

You try to load your website, and you are greeted by bold text saying “Error Establishing a Database Connection.”

Unlike other errors, this one is very specific. It means your website (the frontend) cannot talk to your database (the backend where your content lives). If the bridge is out, no traffic can pass. Let’s fix that bridge.

Broken connection between WordPress and Database
Photo by Yuriy Vertikov on Unsplash

Why is this happening?

Incorrect Login Credentials: You moved servers or changed a password, and wp-config.php wasn’t updated. Corrupted Database: A hack or a bad plugin messed up the tables. Server Down: Your web host’s database server is offline.

Solution 1: Check Your wp-config.php File

This is the most common culprit.

  1. Open your wp-config.php file via File Manager.
  2. Look for these lines:
define('DB_NAME', 'database_name_here');
define('DB_USER', 'username_here');
define('DB_PASSWORD', 'password_here');
define('DB_HOST', 'localhost');
  1. Ensure these details match exactly what is in your hosting dashboard under “MySQL Databases.”
Checking database credentials in hosting dashboard to fix WordPress connection error
Photo by Luke Chesser on Unsplash

Solution 2: Repair the Database

If your credentials are correct, the database might be corrupted. WordPress has a built-in repair tool.

  1. Add this line to your wp-config.php file:
define('WP_ALLOW_REPAIR', true);
  1. Visit this URL: http://yoursite.com/wp-admin/maint/repair.php
  2. Click “Repair and Optimize Database”.
  3. Important: Remove the line of code from step 1 immediately after you are done!

Solution 3: Check With Your Host

If the above fail, your hosting provider might be experiencing a surge in traffic or a server outage. Contact their support immediately via live chat.

Frequently Asked Questions

How do I know my Database Username?
Log into your cPanel or hosting dashboard and look for “MySQL Databases.” It will list the users assigned to your database.

Is this error permanent?
No, but you should fix it immediately as your site is offline to visitors.

Conclusion

Database errors look technical, but they are usually just a wrong password or a typo in a file. Double-check your credentials, and you’ll likely be back online in minutes.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *