Get Appointment

We have received your message and will contact you soon.

Thank you for choosing prositeweb, your web development agency in Montreal. Please call us at +1 (514) 548-2165 if you need immediate support.

How to fix "error establishing a connection to a WordPress database"?

If you are not used to handling databases, you may be surprised to see the message “Error establishing connection to a WordPress DB”. This commonly happens when you migrate your WordPress website to a new server. Alternatively, there may be a problem with your database. In this article, we will observe how to fix this type of problem. Before talking about the approaches for a solution, we will see why it happens.

The causes of the problem "Error when establishing a connection to a WordPress DB"

Such an error can occur in the following 4 cases:

  • You entered your database connection information incorrectly.
  • A difficulty has occurred with your database server.
  • Your database is corrupted.
  • You don't have to change hyperlinks if you're using multisite WordPress.

As we can see, the problem is usually due to the database. We will therefore see how WordPress establishes the connection with a database.

How does WordPress connect with a database?

To establish a connection between your web server and your database, WordPress uses the wp-config.php file. Indeed, in the main WordPress directory, you will see a wp-config.php file. This file has, for example, several functions and constants. Among the constants, we can mention the connection to the database, the codes to handle errors or the encryption data. Database To connect to the database, you usually need to create the data in your server. Then it will be a question of adding them in line 23, 26 and 29. If this information is not available or is wrong, you will see the error message when accessing the website. We will now explore how to fix these problems.

You entered your database connection information incorrectly

If you mistype your database information, you will inevitably get an error. To do this, you simply need to review whether you have the correct database name, username or password. Quite often, if you've made a mistake on the password, you need to reset and replace to fix the problem.

A difficulty has occurred with your database server

For some reason, the website may have trouble connecting to the server. In this case, resetting the server might fix the problem. If you don't have access to the reset feature, you can just contact your provider.

Your database is corrupted.

Sometimes the database gets corrupted. There can be several reasons for this.

  • Server configuration
  • The data encryption or decryption system has changed.
  • An error occurred during updates.

To fix such problem, you need to use the database repair feature. All you have to do is add the code below to your wp-config.php file and then reset your website.

 define('WP_ALLOW_REPAIR', true);

When you add this code, all you have to do is launch the URL of your website and options will appear on the screen,

You don't have to change hyperlinks if you're using multisite WordPress.

When you have a WordPress website with multi-site functionality, you may get this message when migrating to a new domain name. In this case, you will simply have to modify the URL in the wp-config.php file as well as in the wp_options, wp_site, wp_blogs tables. To modify the links in the tables of your database, you can only go to the space for managing your DBs. Then you need to do the queries below. Change the URL in the wp_options table

 UPDATE wp_options SET option_value='' WHERE option_name=''

In this expression, is the initial site URL and is the new website URL. You must adapt this query for the wp_site, wp_blogs tables


In summary, fixing the “Error establishing a connection to a WordPress DB” problem comes down to exploring the different approaches above. If in the end you find that adding the correct database information does not fix the problem, it is inevitably related to the web server. In this case, we recommend that you see with your supplier. You can also contact us ; it would be a pleasure to assist you.

Share :


How to create a website from $800 with our resources
27 January 2023
The 7 Best Multi-Vendor Sites for E-Commerce Owners
01 July 2020

Do you have a project in mind? Contact our web agency for a free evaluation.

We are the experts in creating websites, online stores and functionalities for websites based in Montreal. Contact us today to create your website starting at $1,200.