Error establishing a database connection

Error establishing a database connection

Error establishing a database connection


“The error of establishing a database connection” is probably one of the most common and scary mistakes that WordPress users may encounter. It’s really a close link with the white screen of death (WSOD). This error means that your website no longer communicates or no longer has access to your WordPress database. As a result, your entire website goes down. This is not something to be taken lightly and you should try to resolve it immediately as it can directly affect your sales, traffic and analytics.

But do not worry, today we’re going to discuss some of the common scenarios that cause this error, as well as some simple ways to get your site up and running in no time.

Methods to fix Error establishing a database connection

1. Determine Error Establishing a Database Connection

Are you experiencing the same error when trying to enter the website URL (front-end) and when trying to connect to / wp-admin / (back-end)? If the error is the same, that is, an error while making a connection to a database, go to the next step.

However, if you encounter the following error when trying to connect to / wp-admin /, your database has been corrupted:

“One or more database tables are not available. The database may need to be repaired “

In your root directory of the WordPress file, you must locate your wp-config.php file. You must do this to enable the built-in WordPress Repair feature.

Start Filezilla -> (WordPress installation folder) -> public_html

Right-click the wp-config.php file and select a code editor, such as Sublime Text Editor, to open the file.

After opening the wp-config.php file, add the following line to the bottom of the file:

define (‘WP_ALLOW_REPAIR’, true);

Now navigate to:

(Replace “” with your current URL)

2. Repair WordPress Database

You will see the options mentioned above. We recommend that you choose the option “Repair and optimize the database”. Although it takes longer, it is a more complete attempt to solve the problem.

This repair page is accessible without the need to connect, which creates a security problem. Immediately after the repair and optimization, delete the line of code that you added to the wp-config.php file.

Did this method correct a WordPress error when making a connection to a database? If so, congratulations! Otherwise, continue reading this guide to find another fix for the error.

3. Reset Username and Password

You must ensure that the username and password of your wp-config.php file match those of phpMyAdmin. In our case, it’s MySQL Access.

If the username and password do not match, open your wp-config.php file and modify it to include the values ​​in the “MySQL Access” panel.

That’s it! If you tried to do it via cPanel, you would have to do a lot more work.

4. Database Host Value

The fourth important value in the wp-config.php file of WordPress is DB_HOST. For most web hosting providers, this value should be localhost, which is the default file value.

If you have completed all of the above steps and the database connection error in WordPress persists, check this official list of DB_HOST values ​​for different web hosting providers. Alternatively, you can contact your web hosting provider and ask them to provide you with the DB_HOST value and enter it in the wp-config.php file.

We hope you find this guide useful and that you have successfully resolved the WordPress error when establishing a database connection problem.