How to Fix the Error ‘Establishing a Database Connection’ in WordPress

A common reason that causes the issue ‘Establishing a database connection’ is an error in the WordPress credentials in the configuration file. Here are some easy ways to tackle the issue.

Incorrect database credentials

Log into your SiteGround Client Area > Websites > Site Tools next to the desired website. Then, go to Site > File Manager > public_html folder. Then look for the file wp-config.php. Before making any changes to it, it’s best to keep a backup of the file just in case. To do that, right-click on the file, select Copy, and rename the copied version to wp-config-backup.php.

Then, right-click on the original wp-config.php file and select Edit.

Scroll down to the lines which contain your database username, password, host and database name. You will have to make sure that these credentials are correct.

To check the values, open the MySQL tool in a separate tab in your browser. Right-click on MySQLand select Open Link in a New Tab.

On the main page of the MySQL tool, you will see the name of the database.

Copy the database name and replace it in the wp-config.php file to make sure it is the correct one.

Then, go again to the MySQL tool and click on the tab Users in order to see your database user. Copy the name of the user and paste it in the wp-config.php file where the DB_USER is described. After making the changes, save the file and reload your website to check if the error has disappeared. If it is still present, then the problem could be related to the password.

You can change the password directly from the MySQL Manager > Users > Manage Users > Actions menu > Change Password.

Create a new password and copy it in order to paste it too in the wp-config.php file.

Incorrect database user privileges

Note that if your user does not have the required privileges over the database, this might also cause the error. To check that, go to the MySQL Manager > Users > click on the blue link of the database under Database Access. Then, click on the Manage Access icon.

The privileges should be set to All Privileges.

Corrupted database

Note that this step is only relevant if the application database is using MyISAM as a storage engine. 

The error ‘Establishing a Database Connection’ can also be caused by a corrupted database. To fix that problem, you need to insert the following line of code in the wp-config.php and reload the website in order to repair the database:

define('WP_ALLOW_REPAIR', true);

You can also check this video tutorial:

Share your love
Default image
pidringatwork
Articles: 6

Leave a Reply