Error establishing connection with the database

A very common error in WordPress occurs when our files cannot connect to the database. Do not panic! This error is also usually very easy to solve following these steps.

Why does this error occur?

I know that you want to get to the point and solve your error directly and as soon as possible, but first you have to understand why it happens so you can solve it correctly.

Any installation of WordPress consists of a set of files (divided into different folders) and a database with several tables. All this is hosted by your hosting provider.

For WordPress to work properly, it has to be all connected to each other, and this is achieved thanks to the wp-config.php file

This file is located in the root directory of your hosting account and contains the necessary data for WordPress to connect to the database, which will be created in another folder (you do not need to touch it a priori)

The error, therefore, occurs when the access data you have in that file is not what is needed to access the database.

As a general rule, you should have typed this data at the beginning of the whole, when you installed WordPress for the first time. However, it is possible that, for some reason, they have been deconfigured so you will have to review them manually to make sure they are correct.

The wp-config.php file

This file has different information about the configuration of WordPress, however, you should go to the section where it talks about “MySQL settings” since that is where the fault lies.

To access this file you can do it from the Control Panel of your hosting provider, inside the File Manager, and edit it with the “Code Editor”, for example.

There you have to locate 4 fundamental parameters, which are what I explain below (be careful not to delete the quotes or any punctuation at the time of modifying data!)

[et_bloom_inline optin_id = “optin_10”]

Name of the MySQL database

define(‘DB_NAME’, ‘xxxxxxxxxxxxx‘);

User name of the database

define(‘DB_USER’, ‘xxxxxxxxxxxxx‘);

Counterclaim access to the database

(Do not confuse with the password to access WordPress)

define(‘DB_PASSWORD’, ‘xxxxxxxxxxxx‘);

Address of the server where the database is located

define(‘DB_HOST’, ‘localhost‘);

 

In the four options, you have to check that what I have written in red letters is correct. That is, it corresponds with the configuration of your database.

The normal thing is that you no longer remember the parameters that you put … or that if you chose an automatic installation of WordPress you would not even type them, but that it was the CPanel itself.

Do not worry, there is a way to check it.

Check MySQL data

Now you must return to your CPanel (or the control panel used by your hosting provider) and look for the icon that says “MySQL Databases”. Access that icon

The normal thing is that you only have one created, so you should follow these steps:

  1. Go down to where it says “Current Databases”.
  2. Search where you name the database
  3. Check that this name is the same as you have in the wp-config.php file in the ‘DB_NAME’ section
  4. Save the file wp-config.php (only if the data was wrong and you have modified it)
  5. Reload your WordPress page

If the error has not been solved, we have to continue on.

  1. Keep going down to where you put current users.
  2. Check that the data with your config-php file and make sure it is what is written next to ‘DB_USER’
  3. Save the file wp-config.php (only if the data was wrong and you have modified it)
  4. Reload your WordPress page

If the fault was not there either, we have to continue testing. Let’s go for the password. The disadvantage, in this case, is that we can not find out what you had, but it is possible to modify it with a new one.

  1. Click on ” change password “, next to current users,
  2. Choose a new password
  3. Write the same in your wp-config file, next to ‘DB_PASSWORD’
  4. Save the file wp-config.php (only if the data was wrong and you have modified it)
  5. Reload your WordPress page

Has it been solved? We are running out of possibilities … We still need to check if the prefix of the tables included in the database is correct.

Check data in phpMy Admin

This check is very simple, we are only going to check a data. For this you need:

  1. Go back to your CPanel and choose the icon “phpMy Admin”
  2. In the new screen, display your database in the list on the left
  3. You will see a lot of tables, and all of them, you will see that they start with xxxx_
  4. Go to your wp-config file and look for $ table_prefix = ‘ xxxx_‘; (Change it if it’s different)
  5. Save the file wp-config.php (only if the data was wrong and you have modified it)
  6. Reload your WordPress page

If even after making all these checks has not solved the error, you can only think that your hosting provider has changed the location of the server where your database is hosted (although it is not usual)

Check the location of the database

In this case, you have to contact your hosting provider, yes or yes, to ask the address where your database is hosted and put the ip or address that you provide within your file wp-config.php

Specifically, you have to search define (‘DB_HOST’, ‘ localhost ‘); and write the address where it says ‘localhost’ (this word means that your database is on the same server as your WordPress).

One comment

  1. Avatar

    Hi, I do think this is a great website. I stumbledupon it 😉 I will revisit yet again since i have saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to help others.

Leave a Reply

Your email address will not be published. Required fields are marked *