How to Fix the Error Establishing a Database Connection in WordPress

Author

Moch. Nasikhun Amin

Published on

August 9, 2025

Are you seeing the Error establishing a database connection message on your WordPress website? Don’t worry. This article provides a complete guide, explaining what this error means and, most importantly, how to fix it!

This particular WordPress database error prevents your website from fetching and displaying any data. It might be a minor inconvenience if it happens on a local development site (localhost), but it’s a serious concern for a live website as it completely disrupts the user experience.

So, what exactly does Error establishing a database connection mean? What causes this database error on a WordPress site, and how can you resolve it? Let’s dive into the answers.

What Does Error Establishing a Database Connection Mean?

What Does Error Establishing a Database Connection Mean?

The Error establishing a database connection message indicates that your website is unable to connect to its database. As a result, it cannot retrieve the necessary data to display the page.

WordPress uses the MySQL database system to store all of your site’s essential information. This includes content like posts and pages, site settings, user information, and metadata. For instance, when you use the Gutenberg block editor to build pages, all that information is saved in the MySQL database.

This error can occur on any version of WordPress, including the latest ones like WordPress 6.5. However, it’s not a flaw in the WordPress core system itself, debunking a common myth about WordPress. So, what are the actual causes?

Causes of the Database Connection Error in WordPress

While there are several potential reasons for the Error establishing a database connection message, the following are the most common culprits:

1. The Server Is Down

If your hosting server is down, your website’s database becomes inaccessible, triggering the connection error. This is a common issue for live websites.

A server can go down for several reasons, including a sudden surge in visitors (overload), hardware failure, or a lack of resources like disk storage.

2. The Database Is Corrupted

Another frequent cause is a corrupted database. This error often appears after you’ve performed an update or installed new files, such as a plugin that conflicts with another one, leading to database corruption.

3. Incorrect Login Credentials

If your WordPress site is using the wrong credentials to access the database, the connection will fail. These credentials include the database username and password.

This can happen on both a local development environment and a live website. For example, if you installed WordPress on XAMPP and the site suddenly shows a database error, incorrect credentials could be the reason.

If you’re facing this error, how can you fix it?

How to Fix the Error Establishing a Database Connection in WordPress

Here are several methods you can try to resolve the Error establishing a database connection, from checking credentials and repairing corrupted files to creating a new database.

1. Double-Check Your Database Credentials

Before attempting more complex solutions, the first step is to verify your database login credentials.

These credentials—database name, username, password, and host—are stored in your wp-config.php file. You need to ensure they are correct.

How you access this file depends on whether your site is on a local server or a live server:

a.) If Your Website Is on a Localhost

  • Using File Explorer: Navigate to the directory where you installed WordPress on your local machine. If you’re using software like XAMPP or WampServer, this is typically inside the htdocs or www folder. You will find the wp-config.php file in the root of your WordPress installation.
  • Using a Text Editor: Open your preferred text editor (like Visual Studio Code, Sublime Text, or Notepad++). Use the Open File or Open Folder feature to navigate to your WordPress installation directory and open wp-config.php.

b.) If Your Website Is Live

Using cPanel or Another Hosting Control Panel:

  1. Log in to your web hosting control panel (e.g., cPanel).
  2. Look for and open the “File Manager.”
  3. Navigate to the directory where WordPress is installed, usually public_html or a subdirectory within it.
  4. Locate the wp-config.php file and use the built-in text editor to open and view its contents.

Using an FTP/SFTP Client:

  1. Open your favorite FTP/SFTP client (such as FileZilla, WinSCP, or Cyberduck).
  2. Connect to your web server using the FTP/SFTP details provided by your hosting company.
  3. Navigate to your WordPress installation directory.
  4. Find and download the wp-config.php file to inspect it.

Once you have access, compare the credentials in the file with the ones provided by your hosting provider to ensure they match.

2. Repair the WordPress Database

If checking the credentials didn’t solve the problem, the next step is to repair your WordPress database.

Besides seeing the error on the front-end, you might also see a message like One or more database table are unavailable when trying to access your admin dashboard. This is a clear sign of database corruption.

To fix this, follow these steps:

  1. Access your wp-config.php file (located in public_html or your root WordPress folder).
  2. Add the following line of code to the bottom of the file:
define(‘WP_ALLOW_REPAIR’, true);

Save the file and reload your website. You should now see a page with options to Repair Database or Repair and Optimize Database. Choose one to start the process, which may take some time.

Once the repair is complete, it is crucial that you remove the line of code you just added from wp-config.php. Leaving it in poses a security risk, as it allows anyone to access the repair page.

3. Check for Corrupted Files

If the error persists, a corrupted theme or plugin file might be the cause. Think about what you did right before the error appeared. If you recently installed a new WordPress plugin, it’s the most likely culprit.

To fix this, you can deactivate the problematic plugin. If you can’t access your admin dashboard, you’ll need to do this via FTP or your hosting’s File Manager by renaming the plugin’s folder (e.g., from plugin-name to plugin-name-old). If a theme is causing the issue, you can try switching to a default WordPress theme (like Twenty Twenty-Four) using the same method.

4. Check Your Database Server

Another possibility is that your database server itself is the problem. A common scenario is a sudden spike in website traffic that overloads the server, making it unresponsive.

When a database server is overloaded, it can lead to performance degradation and connection failures. If you suspect this is the case, contact your hosting provider. They can confirm if the server is down or struggling and may recommend upgrading your hosting plan to handle the load.

5. Create a New Database

If all the methods above fail, your last resort is to create a new database. You can follow a tutorial for this process.

However, before you do anything, make sure you back up your WordPress site completely. This is a critical safety net to ensure your data remains safe.

Have You Fixed the WordPress Database Error?

This guide has walked you through the definition, causes, and solutions for the error establishing a database connection in WordPress.

Now that your WordPress site is back up and running, it’s a great time to learn how to create an XML sitemap. This will help improve your website’s SEO performance.

However, if you’re still facing challenges with managing your WordPress site, consider partnering with the Tonjoo team. With over 10 years of experience developing WordPress-based websites, we’re here to help.

Feel free to contact us through the Tonjoo Contact page and let’s optimize your website together.


Read similar articles by Moch. Nasikhun Amin on the Tonjoo blog about WordPress, WooCommerce, plugins, and other web development topics.


 

Updated on August 10, 2025 by Moch. Nasikhun Amin

Mari Bekerja Sama!

Wujudkan situs web impian Anda bersama kami.

Contact Us