WebHostingPeople Blog

  • Domains
    • Shared Hosting

  • Cloud VPS
  • Servers
    • Client Area Login

How Can We Help?

How To Fix “Error Establishing Database Connection” In WordPress

You are here:

In this tutorial, we will learn how to fix the issue of error establishing a database connection in WordPress

WordPress is the most popular Content Management System (CMS). In the web industry, WordPress and its various features are a topic of discussion. There are several common errors in WordPress. These errors can be resolved by following certain steps. There can be multiple solutions to these common errors.

In this article, we will see how to resolve the error of establishing a database connection in WordPress. If you are a WordPress user, it is important to carefully read this article. Have you ever encountered the following page when trying to access a WordPress website?

Database Error

This is the screenshot displayed when a database error occurs. Let’s understand why this error happens and what it means.

Why Does This Error Occur?

As the error message suggests, WordPress is unable to establish a successful connection with the database. WordPress relies on a database to function, as it is a database-driven application. When WordPress fails to connect to the database, this error occurs. Below are a few common issues that may lead to this error.

1) Your database service is down

2) Incorrect database and login details

3) A corrupted database

The database service is down

The database service might be temporarily unavailable. If you are using MySQL databases, check if MySQL is up and running. It is possible that the server where your database is stored is experiencing downtime.

Wrong credentials

As we know, the database details such as the database name, username, and database user password are defined in the wp-config.php file. If there is any discrepancy in these details and the actual ones, it can result in this error.

The corrupted database

If the database is corrupted, it can trigger this error.

Steps to Resolve the Error

1) First, ensure that the error appears on both the front end and back end of the website. The back end refers to your website dashboard. You can access the back end using the URL: http://yourdomain.tld/wp-admin. If you see the same error on this page as well, proceed to the next step. If you see an error message like “Multiple database tables are unavailable. The database may need to be repaired.”, please continue with the following steps.

Database Connection

This indicates that the database is corrupted. You can resolve this by clicking on the “Restore Database” or “Restore and Optimize Database” option. You are free to choose either of these options.

2) The next step is to check the database details provided in the wp-config.php file. The first thing you need to do is open the wp-config.php file. If you have SSH access, you can use an editor like “vi” from the terminal. However, SSH access may not be available if you are using our shared hosting plans. In that case, you can open the file using the user-friendly file manager feature in cPanel. You can find the file manager under the “Files” section. You need to open the wp-config file located at WordPress_root_directory/wp-config.php. Once you have opened the file, you will find the following fields:

define(‘DB_NAME’, ‘database-name’);

define(‘DB_USER’, ‘database-username’);

define(‘DB_PASSWORD’, ‘database-password’);

define(‘DB_HOST’, ‘localhost’);

Carefully review these lines and verify if the database name, database user, database password, and the database host fields match the actual details. If there is any difference, you can set the correct values for the database name, database user, and password from the cPanel interface. Alternatively, you can update the wp-config.php file with the correct values, but it is not recommended to edit the configuration file if you are not familiar with it.

If you need further assistance, please contact our support department.

Post Your Comment