How to Fix the Error Establishing a Database Connection in WordPress

Introduction

The message:

Error Establishing a Database Connection

is one of the most common WordPress errors.

This error occurs when WordPress is unable to communicate with the website database.

When this happens, visitors may be unable to access the website and administrators may be unable to log into WordPress.

This guide explains the most common causes and troubleshooting steps.


Why This Error Occurs

WordPress stores website information in a database, including:

  • Pages
  • Posts
  • Users
  • Settings
  • Comments

If WordPress cannot connect to the database, the website cannot load correctly.


Common Causes

The most common causes include:

  • Incorrect database credentials
  • Corrupted database
  • Database server issues
  • Website configuration errors
  • Resource limitations

Step 1 – Determine Whether the Website Is Affected

Visit:  https://yourdomain.co.za

Then visit:  https://yourdomain.co.za/wp-admin

If both display the database connection error, WordPress cannot communicate with the database.


Step 2 – Determine Whether Recent Changes Were Made

Consider whether any of the following occurred recently:

  • Website migration
  • Database changes
  • WordPress update
  • Plugin installation
  • Manual configuration changes

Recent changes often help identify the cause.


Step 3 – Check Other Websites on the Hosting Account

If you host multiple websites, check whether other websites are functioning correctly.

If multiple websites are affected, the issue may be server-related.


Step 4 – Review Database Configuration Changes

If database settings were recently modified, verify that the correct database information is being used.

Database settings are stored within the WordPress configuration files.

Incorrect settings can prevent WordPress from connecting successfully.


Step 5 – Restore a Backup

If the problem occurred after recent changes, restoring a known working backup may be the quickest solution.

Open your browser and visit:

https://cp.yourdomain.co.za

Enter your DirectAdmin username and password.

Click: Log In

Click: Extra Features

Then click: WordPress Manager by Softaculous

Locate your WordPress installation.

Click: Restore

Select a backup created before the problem occurred.

Click: Restore Installation


Step 6 – Test the Website

After restoring a backup or correcting configuration issues:

Visit your website.

Verify that:

  • Pages load correctly.
  • Images display correctly.
  • The administration area is accessible.

Database Corruption

In some cases, the database itself may become corrupted.

Symptoms may include:

  • Database connection errors
  • Missing content
  • Administration area errors

If database corruption is suspected, restoring a backup is often the fastest recovery method.


Hosting Resource Issues

Occasionally, temporary resource issues may affect database availability.

Wait a few minutes and test the website again.

If the issue persists, contact support.


Best Practices

To reduce the risk of database problems:

  • Create regular backups.
  • Avoid unnecessary configuration changes.
  • Keep WordPress updated.
  • Keep plugins updated.
  • Test major changes carefully.

Regular backups provide the fastest recovery option if problems occur.


When to Contact Support

Contact support if:

  • The error persists after restoring a backup.
  • Multiple websites are affected.
  • You recently migrated the website.
  • The database appears to be corrupted.

Provide:

  • The website address
  • Any recent changes made
  • Screenshots of error messages where possible

Conclusion

The "Error Establishing a Database Connection" message indicates that WordPress cannot communicate with its database.

In many cases the issue can be resolved by reviewing recent changes, restoring a backup or correcting database configuration issues. If the problem persists, support may be able to assist with further investigation.

  • database connection errors, wordpress database, website troubleshooting, wordpress troubleshooting
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

What to Do If You Forget Your WordPress Password

Introduction If you cannot log into your WordPress website because you have forgotten your...

What to Do If You Are Locked Out of WordPress

Introduction There are several reasons why you may be unable to access your WordPress...

How to Fix a White Screen in WordPress

Introduction A white screen in WordPress, often referred to as the White Screen of Death (WSOD),...

How to Disable a WordPress Plugin When You Cannot Log In

Introduction Sometimes a plugin can cause problems that prevent you from accessing either your...

How to Recover a Deleted Page or Post in WordPress

Introduction Accidentally deleting a page or post is a common mistake in WordPress....