Fix Error Establishing a database connection in WordPress
What does this error message mean?
You can enter your site at any time and find this message, and it may be permanent and may be intermittently recurring. In the event that this problem exists intermittently on the site, so that it appears and disappears throughout the day at any time without your intervention, then write to the hosting company to check the database servers, you may be exceeding your limit of connections with the databases, or there may be a problem with the server itself .
What does this error message mean? #
This message means that WordPress is unable to connect to the database for some reason. This may be the reason that the script is faulty or the data is incorrect. In this explanation, we learn how to examine all the causes related to the problem to find the cause of the problem.
First: Make sure that your server is healthy and there is no problem with the database hosting server #
In the event that there is a problem with the server hosting the database so that it has stopped working, in this case it is normal for you to see this message. In this case, you will have to contact the hosting company and ask them to solve the problem. If there is no problem with the server hosting the databases, then you should follow the following steps to start checking your site.
Second: Make sure that the database connection data in the wp-config.php file is correct #
In this file you will find the data for the database, the username for the database and the password. In this case, you will have to make sure that the data written in this file is correct without any errors. And if you are not sure of the password for the username, you can use the same password found in the wp-config.php file and set the password for the username in the cPanel to the password in the file, to ensure that it matches. If the data is correct, follow the next step.
Third: Ensure that the username of the databases is valid #
The database connection data may be correct and there are no errors, but the problem still exists. In this case, you will have to examine one of the most important points that many site managers overlook, which is the user name permissions. You must have all the permissions for the database user name to properly connect with the database, and you can complete this easily through the following steps:
Follow these steps to solve the problem: #
1- We enter the cPanel control panel, or the hosting control panel, through which you can manage databases.
2- Log in to the databases or Mysql Databases.
3- Click on the username next to the database it is linked to.
4- A table of permissions for the database user name will appear, select All Privileges or All Privileges.
5- Click on Save Now.
In this way, you have given the username all the necessary permissions to connect and modify the databases. If the problem still exists, move on to the next step.
Fourth: Attempting to repair the site through the repair file in the control panel #
The WordPress script provides you with the ability to self-repair the script in the event of a problem in the databases, and you can complete this matter through the repair file in WordPress, and to be able to do this, follow the following steps:
Follow these steps to solve the problem: #
1- Entering the cPanel control panel or any control panel through which you can manage files or FTP.
2- Open the wordpress config file to edit it
3- wp-config.php- Add the following line, immediately after the starting line in wp-config.php
define(‘WP_ALLOW_REPAIR’, true);
4- Save the file, and open the following link in your browser on your website link
http://www.mydomain.com/wp-admin/maint/repair.php
* Make sure to change mydomain.com to your site’s url, and if you are installing WordPress on an internal directory, make sure to write the url to the wordpress directory, before /wp-admin.
5- From the page that will appear to you, click on Repair Database or Repair Database.
Review your site now. If the problem is resolved, be sure to delete the line added to the wp-config.php file after you are done. If the problem is not resolved, make sure to cancel it first and then continue with the following steps.
Fifth: Attempting to disable the add-ons installed from within the cPanel #
In rare cases, plugins may be the problem, try disabling the plugins used within WordPress, and you can do this simply by changing the name of the wp-content/plugins file to any other name, and then reviewing the site, if the problem is resolved, it means that one The add-ons inside the site are the cause of the problem, and if the problem is not resolved, please continue to the next steps.
Sixth: Last attempts to solve this problem #
Since you have reached this stage, the traditional solutions no longer work, let’s try some tricks that you can use.
– Try to use a password for the database username without any special characters such as โ(*#@%!โ Use only letters and numbers.
– Try replacing the wp-config.php file with a new one, and you can get it from any copy, but make sure to keep a copy of the old file to restore it if the matter does not work. update, then log in to the wordpress control panel and it will ask you to update the script.
If all these attempts are unsuccessful, it seems that the problem is not direct, and you will need a specialist to review the site himself to examine the cause
Explanation completed Fix Error Establishing a database connection in WordPress