When you are visiting any WordPress related blog then you may experience the error in establishing the database connection in WordPress.
You will have the information about the three things:
- Meaning of “error in establishing the database connection in WordPress.
- Reasons why all these messages appear.
- And fixing of this error in WordPress.
Error Establishing A Database Connection
The working of WordPress is based on two essential parts:
- Your files- it includes the WordPress software, themes, plugins, and all your media uploads.
- Your database: the place where your all data of your post and pages are actually stored including the precious information.
The reason for the error established:
There can be many reasons behind this message. But most of the time it is done by the corrupt database. It also occurs when there will be corrupt WordPress core files and having problems with your web host. The major reason behind this problem is the incorrect database configuration details in your wp-config.php file.
You can identify these problems and perform a test to isolate the problem.
Fixing of the Error Establishing A Database Connection:
Potential fix 1: ( make sure and check if you can still access the WordPress dashboard)
The first thing to do when this message appears on the front end of your site then, check it down that you are getting the same error when you are trying to access your wp-admin dashboard. If the problem exists with that dashboard also then you can skip to the next step. You have done the eliminating of the problem as a potential cause,
If the message is not same as the above and something like this written in screen “ the database need to repair” then you can go with steps given below.
Step 1:
Just turn on the repair utility in the wp-conf.php file:
Before starting this process, we need to edit the wp-config,php file for your site. There is another step to do that:
- The connection of your site with the FTP.
- And the use of cPanel’s built-in File manager tool.
The same address as the folder contains wp-admin and wp-content is where your wp-config.php file is actually located.
You will have to add the shortcode to the editing your wp-config.php.
Define( ‘WP_ALLOW_REPAIR’, true );
Before going further, save the changes you have made till now.
Quick links:
- {Latest 2018} The BEST Appointment Booking Plugins for WordPress
- {Latest 2018} List of Best Top WordPress Slider Plugins You Should Check
- Beaver Builder vs Thrive Content Builder Vs Visual Composer: Who WINS??
- ThirstyAffiliates Link Cloaker WordPress Plugin Review: How to Use it
Step 2:
The running of the automatic database repair utility
After the adding of the code snippet given above you can now access the WordPress database repair tool on.
YOURDOMAIN.com/wp-admin/maint/repair.php
Just click on the repair database to start the tool. After the tool fixes all the problems, your site will be completely working again. Then you should return to your wp-config.php file and remove the code you have just added to the repair utility.
Potential Fix 2: (Go and check your database login credentials)
Before going on this step ensure that your database is not corrupted and also check that your database login credentials are working.
If somehow these data is not matching with the database credentials which you have created via your dashboard. Due to that WordPress will not be able to access your database. Just use notepad and write down this code.
</php
$link = mysql_connect(‘localhost’, ‘mysql_user’, ‘mysql_password’);
If (!$link) {
die(‘Could not connect: ‘ . mysql_error());
}
Echo (‘Connected successfully”;
Mysql_close($link);
?>
Just replace MySQL with mysql_password with the actual username and password. Then you have to upload that file to your website with the help of cPanel or by FTP.
YOURDOMAIN.com/databasecheck.php.
If “connected successfully” appears then your database credentials are working and just go to the next step.
But you have got a message saying access denied then there must be a problem with the database credentials.
Just go and create new database credentials for your WordPress site.
1. Go to my SQL database in cPanel:
Just keep in mind that your host is using the cPanel, just go and create the MySQL Database option in the dashboard.
2. Create a new user:
Just go to the MySQL and find the box to Add a New User, enter new username and password.
3. Just add a new user to the database:
After creating a new user, you can now go to the Add a User to a database option and add the user to your WordPress site database.
Use ALL PRIVILEGES on the next line.
4. Go and update the wp-congig.php file with the new database user:
Just to finish this process you have to go back to your site wp-config.php file and just update the DB_USER and the DB_PASSWORD.
Potential Fix 3 (Reupload the core WordPress files) :
If somehow all the above methods are not working to fix it then you should go with this one.
Just upload a fresh copy of WordPress to your site. It will not affect your existing content, plugins, and themes.
Just update the version of WordPress by going to wordpess.org.
All you need to do now is to extract the zip file and delete the wp-content folder along with the wp-config-sample.php file.
Also, read:
- How To Change WordPress Admin Login URL With WordPress Plugins
- Should You Invest In Managed WordPress Hosting 2018: Pros And Cons
- Don’t Miss This Winter Sale from TemplateMonster: Buy a Bodacious Theme with 35-45% Discount!
- Best WordPress Membership Plugins TO Create A Membership Site in WordPress
Upload the remaining file via FTP on WordPress. Just overwrite the duplicate files.
This will make none of your core files are corrupt, this will fix all the issue.
Potential Fix 4 (Try to speak with your host):
If somehow all the methods are failed and you may deal with some issues. Some of the hosting potential problems are:
- Your database server is down
- Your database has somehow met its quota
Finally, if you are having such problems then you should go to the host customers care.
Now you are able to fix the error establishing a database connection message. Do share it on all the social media platforms. Let me know if there is some problem.
Hi
This is prabhu. i’m a web developer and i work with wordpress. This article about How To Fix “Error Establishing A Database Connection” in WordPress is really good. as a wordpress users everyone would have faced this issue atleast once. as a beginner it will be a nightmare. But this article is really good to know how to fix this issue. Thanku so much
Hey, Prabhu Ganesh
Nice to hear that !!
Nice Artical ….. Helpful For Me … Thanks Again
Most Welcome !!
We are here to help you man.