• Get In Touch

WordPress showing ‘Error Establishing a Database Connection’

Using Wordpress? Get our lightening fast Wordpress Optimised Hosting.
Get Wordpress Hosting

If your WordPress website is reporting that there’s an error establishing a database connection, you can run through various steps to ensure that the database connection details are setup correctly, that the database exists, and even change the database password if you think that this is the problem.

Check WordPress wp-config.php database credentials

In your WordPress files on your server, there is a file named wp-config.php where you can review your WordPress database connection information.

To access this, the first step is to log into your cPanel account. If you are unsure on how to do this, please view the following help article – ‘How to log into cPanel‘.

In cPanel, scroll down to the ‘Files‘ section and choose ‘File Manager‘.

The file manager has access to all of the files on your server, including your WordPress files which is where we need to view the wp-config.php file.

Using the left directory listing, open the ‘public_html‘ folder and then click onto the folder that contains your WordPress installation.

Once in the WordPress folder, locate the wp-config.php file and mouse click onto it.

Choose ‘Edit‘ from the top menu.

Open the file in the text editor by selecting ‘Edit‘.

When the file loads, review the section for the ‘MySQL settings‘. This will contain the database name, user and password that it has been configured to use in order to gain a database connection. These are shown as in our example:

  • define(‘DB_NAME’, ‘example_wp156’); – the database name consists of our example account username ‘example’ followed by an underscore and the database name alais ‘wp156’.
  • define(‘DB_USER’, ‘example_wp156’); – the database user, again our example account username and underscore, followed by the database username alais ‘wp156’.
  • define(‘DB_PASSWORD’, ‘9SyPd2((8R’); – the database password.
  • define(‘DB_HOST’, ‘localhost’); – the database host, always localhost.

Please note that your database connection details will differ from what has been shown here.

Check phpMyAdmin for the database

Now that we know what database WordPress is trying to connect to, lets check that the database exists.

Whilst still logged into your cPanel account, scroll down to the ‘Databases‘ section and choose ‘MySQL Databases‘.

At the top under the ‘Current Databases‘, you should find your database listed to verify the database as per the wp-config.php file is correct.

If you do not have any database listed, you will need to create the database and then import your WordPress database into it. The following help articles will assist with these procedures:

By creating a new MySQL database, you will need to update the wp-config.php that was earlier viewed as per the new MySQL database and user that you create.

If you can see your database and you believe that your wp-config.php file is correct, but you are not confident the password is correct, you can change this.


Reset the WordPress database password

A database does not have a password, only the database user that has access does which we can reset.

Whilst still in ‘MySQL Databases‘, scroll further down to the ‘Current Users‘ section. Select the ‘Change Password‘ option on the database user as noted from earlier.


Type in your new password for the database user in the ‘Password‘ box and repeat again in the ‘Password (Again)‘ box.

Note that there’s a ‘Password Generator’ option if you would like the system to generate you a strong new password.


Once your new password has been entered, complete the process by choosing the ‘Change Password‘ option.

Now go back to the earlier wp-config.php file viewed in the ‘File Manager‘ and update the database config with the new password that you’ve set. Remember to save the changes to the file before closing the window.


This article helps explain the database information that WordPress has been configured to and how to troubleshoot what might be the problem if your website is experiencing an error establishing a database connection.


Using Wordpress? Get our lightening fast Wordpress Optimised Hosting.
Get Wordpress Hosting

Share this Article!