An error from a website is not unusual. You may see one or two websites showing a
When can you most likely encounter this Error?
The main reason why error establishing a database connection in WordPress occurs is self-explanatory. But how you get this error in WordPress is where it vary. One of the reasons could be is that the input for your credentials is wrong or there has been an alteration. It can also be due to your database server being unresponsive. Or worse is corruption issue with your database. Though most of the time, the occurrence of this kind of error is usually due to server errors, other factors are also put into consideration. Read further down below to take a look on how to solve this problem.
Is it the same error on both front-end and back-end of the website?
In WordPress, wp-admin is where you work through the back-end of your website. If the particular error
First, you have to add the following line in your website’s wp-config.php file. You have to add it just before the line that says That’s all, stop editing! Happy blogging from the said page.
1| define(‘WP_ALLOW_REPAIR’, true);
If you are done, visit the settings by visiting through this page: http://www.yoursite.com/wp-admin/maint/repair.php
Note that as a user, you can access this area of functionality when this define is set even if you are not signed in. This is due to its main intent of repairing a database that is corrupt. It is partly the reason why most of the users are unable to log in successfully when the database is corrupt even if you somehow have managed the connection in WordPress installation. Now, if you are done optimizing and repairing your database, you have to make sure that this is removed from your copy of wp-config.php.
If this step did not somehow solve the problem then continue reading further down below. You might be able to find
Check WP-Config file
In the whole process of database connection in WordPress installation, the wp-config.php file is probably the most essential file. This is where the details for WordPress to connect to a certain database is specified. Just remember that if you change your root password or even the database user password, you also have to change this file. Before doing anything else in the file, you have to check first if the details in wp-config.php is still the same.
Please do note that your DB_HOST value will not always be localhost. It will be entirely different depending on the host. For the popular hosting provider companies such as Bluehost, Hostgator, or even SiteGround, it is localhost. You can also find other hosting reviews here, you might be interested.
There are also other developers who suggests that they somehow were able to solve the problem by replacing the localhost with the IP. This is actually a common issue when running a WordPress on a local server environment. For instance on MAMP, the DB_HOST value when you change the UP may seem to work.
Of course, IP’s will vary for online web hosting services. After making sure that everything else is fine and correct but still the error occurs, then the problem could be on the server side.
Check Web Host
The most common web host is MySQL Server. You will receive the error establishing database connection especially if your website is incurring huge traffic. If this is so, your host server tends to slow down because it will be too much to handle the load. If this happens, you have to contact your hosting provider and personally ask them if your MySQL server is responsive.
You can also check the MySQL server yourself, you can do so by running other sites on the same server. If you are still seeing the same issue, then something is really wrong with your MySQL server. If you only have one website, you can directly go to cPanel and access phpMyAdmin and try database connection in WordPress installation. After connecting, you need to verify if your database had a sufficient permission. You can do this by creating a new file testconnection.php and paste the code that follows:
$link = mysqli_connect(‘localhost’, ‘username’, ‘password’);
die(‘Could not connect: ‘ . mysqli_error());
echo ‘Connected successfully’;
You have to make sure to change both the username and password. If it is connected successfully, then you have sufficient permission and something else is wrong. Double check wp-config.php file to make sure everything is correct, even typo error.
If you still cannot connect thru phpMyAdmin to the database, there is something wrong with the server. However, you do not need to panic as it does not necessarily mean that the server is down. It could also just mean that your user does not have sufficient permission. If this is so, contact your hosting provider immediately to find the problem.
The error establishing a database connection in WordPress installation is truly a frustrating error, isn’t it? Others suggested that some actually have solved the problem by uploaded a new copy of WordPress. It might also work for you.
Hope this article was able to help you resolve your website’s error.