“Error Establishing A Database Connection”. It’s one of the worst nightmares for any WordPress user. This error shows up when your WordPress site is unable to connect to the database to fetch the contents of your website. The database is where all the contents and information of your website is stored.
Needless to say, when this error shows up on your website, you start losing tons of subscribers, visitors, and revenue. Because all your visitors and customers will see is an error message. If you don’t fix this error soon enough, Google and other Search Engines might even stop displaying your website. But don’t worry even if Google stops displaying your website. They will start displaying your website in search results again in a few days once you fix the error.

Get 5 Months Free & 30% Off All Plans.
Click the coupon code to copy and open the link »
If you are seeing this error on your website, later in this article, I will guide you through the exact process we ourselves use to fix this error on our own websites.
What Does “Error Establishing A Database Connection” Mean?
To understand why this error shows up, you will have to first understand how WordPress works. When someone visits a page on your website, WordPress connects to your website’s database, fetches the contents of the page and then displays the page.
The database of your website is where all the information and content of your website is stored. This information includes login credentials for all the users (including your admin account) of the website. And when you see this error, it simply means that for some reason WordPress is unable to connect to the database.
When WordPress is unable to connect to the database, it won’t allow you access to the dashboard as there’s no way for it to verify your login credentials.
To connect to the database, WordPress needs to know the login credentials for the database. And if these login credentials are wrong or missing, it won’t be able to connect to the database.
There is more than one reason why you would see this error. But most of the time, this error happens due to incorrect database login credentials.
What Causes This Error?
This error simply means that WordPress can’t connect to your database to fetch and display the contents of your website. When you see this error on your website, one of the followings can be the case:
- The login credentials of your database are wrong: This is what happens when you change the login credentials of your database and forget to update them in the wp-config file.
- Your database is corrupted: There are a lot of reasons why this could happen to your database. One of which is uploading a badly coded plugin. It can also happen due to an error in the database hosting server.
- Your database server host is down: If you are hosting the database on your own servers, then you will have to contact your developer. But if your web hosting company is responsible for hosting the database, there’s nothing you can do other than calling them and letting them know that it’s down. Most web hosting services offer great support and will fix this problem within minutes.
Whichever the above is the case for you, we will guide you through every possible scenario in this article. In most cases, this error shows up either when the database is curropted or the database login credentials aren’t valid. Both of which are easy to fix and won’t take more than a few minutes to fix.
Before you start making any changes to your website, we would highly recommend you to make a backup or make sure you have a backup of your website. In the unlikely case that you break something, a backup will allow you to go back to the previous state.
Do You See The Same Message On The Back-End?
When you try logging into your website dashboard, are you greeted with a message along the lines of “One or more database tables are unavailable. The database may need to be repaired.”?
If this is the message you see on the back-end, then it simply means that your database is corrupted. On the other hand, if you are seeing the same “Error Establishing A Database Connection.” message, then you can move on to the next section.
Fixing a corrupted database is easy and doesn’t take more than a few minutes. Here’s how you can do it:
First, Login to cPanel, open the File Manager app and then navigate to the WordPress installation folder. Now, find the wp-config.php file, select the edit option and add the following line of code at the end of it:
define(‘WP_ALLOW_REPAIR’, true);
What this line of code will do is it will allow you to enter the database repair mode for your WordPress website.
To start the repair process, visit the following page in your browser:
http://yoursite.com/wp-admin/maint/repair.php
On this repair page, you can either choose repair or repair and optimize. We recommend you to go with repair and optimize, but you should note that it takes more time than just the repair function.
One thing you need to note is that this page is accessible by everyone. You don’t need to login to visit this page and use the repair functionality. So, to make sure the users of your website can’t use this page, you will have to remove the line of code you added to your wp-config.php file once the process is over.
Check If Incorrect Database Login Information Is Causing This Error
To do this, you will have to log in to your cPanel account and open the File Manager app. Then navigate to the installation directory of your WordPress site. Now, view or edit the wp-config.php file to inspect the code.
You should see the login credentials used by WordPress to connect to your database. It should look something like this:
define('DB_NAME', 'database-name-here');
define('DB_USER', 'database-username-here');
define('DB_PASSWORD', 'database-password-here');
define('DB_HOST', 'localhost');
The above four lines contain your database name, username, password and the hostname of the database.
If you find any of these values in incorrect, you should change them with the correct values.
If you don’t know the name of your database, you can find it with PHPMyAdmin. It’s a free application that comes with all hosting solutions.
To use it, you will have to log in to PHPMyAdmin from your cPanel. Once you have logged into the PHPMyAdmin dashboard, you will see a list of databases. One of these databases should have the same name as the value right next to “DB_NAME” in your wp-config.php file. Click the Browse link for the database that has the same name.
Now, you will need to verify if this is the correct database that contains your website’s information. To do this, click the Browse link right next to the “wp_options” table.
If in this table, you can see the name of your website and URL, then it means this is the correct database. If this is not the case, you will have to do the same thing for all the other databases to find the correct database. Once you find the correct database, change the name of your database in the wp-config file with the name of this correct database.
If the name of the database is already correct, then the username and password can be the problem. To check if you are using the correct username and password, create a new file in the installation directory of WordPress and name it “db-check.php” and copy the following code to it:
<?php
$test = mysql_connect('localhost', 'root', 'password');
if (!$test) {
die('MySQL Error: ' . mysql_error());
}
echo 'Database connection is working properly!';
mysql_close($testConnection);
Now, visit the following URL:
http://yoursite.com/db-check.php
If you see an error message, then it means the username or password is incorrect. To fix this, you can create a new username and password with the MySQL Databases app in cPanel.
To do this, open up the MySQL Databases app in cPanel and click the Add New User link. All you have to do now is choose a good username and a strong password, and click the Create User button. These new database credentials are what you will now use.
Now, scroll down to the Add User To Database section, select the username of the user you just created and the WordPress database, and click the Add button. Doing this will add this new user that you just created to your WordPress site’s database.
Now that you have a new user, you will have to update the wp-config.php file with the new database login information.
To do this, open the File Manager app in cPanel, navigate to the WordPress installation directory and edit the wp-config.php file. In the wp-config.php file, change the value next to ‘DB_USER’ with the new username and the value next to ‘DB_PASSWORD’ with the new password.
This should fix the problem if it was due to incorrect database login credentials.
If your website is still showing the same error message, move on to the next section:
Still Seeing The Same Error Message?
If this is the case, then most probably it’s a problem related to your Web Host’s database servers. The only thing you can do in this case is to contact your Web Hosting provider and ask them to fix this problem.
If you have tried all the steps in this article, you shouldn’t hesitate to contact your Web Hosting provider. Because a lot of times this error can be a result some recent update from your Web Host’s side.
Most web hosts offer 24/7 support and are really responsive. If you contact your web hosting service, they will help you find the issue and fix it if it’s on their end. If your web hosting service suggests it’s an error on your side, then you should hire a Web developer to fix the problem.
Alternatively, you can also try reverting your site to a previous backup if you are sure you won’t lose any new data like your latest posts.
92 Comments
Thank you very much, Mohit, for this amazing and informative article. I am writing an article on the topic “How to Fix the Error Establishing a Database Connection in WordPress” Your article gave detailed information on this topic. It helps me a lot to write a good one for my website. I appreciate your hard work. I would be very happy if you have a look at my article: https://wpblog.info/how-to-fix-the-error-establishing-a-database-connection-in-wordpress/
Thanks
Muhaiminul
popular dating sites: onlinelovedating – singles near me
Some are medicines that help people when doctors prescribe.
canadian pharmacy near me canadian pharmacy
Generic Name.
https://mobic.store/# mobic for sale
amoxicillin 200 mg tablet: [url=https://amoxicillins.com/#]where can i buy amoxicillin over the counter[/url] amoxicillin pharmacy price
buy cheap propecia pills get generic propecia without insurance
how can i get generic mobic no prescription: cost generic mobic no prescription – get generic mobic
amoxicillin 500 mg online: [url=https://amoxicillins.com/#]amoxicillin for sale[/url] how to buy amoxicillin online
buy propecia for sale order generic propecia price
https://cheapestedpills.com/# best non prescription ed pills
pills for ed [url=https://cheapestedpills.com/#]how to cure ed[/url] best ed drug
Everything what you want to know about pills.
propecia online buying generic propecia without insurance
safe and effective drugs are available.
http://cheapestedpills.com/# buy ed pills online
buying propecia pill generic propecia no prescription
best treatment for ed: pills for ed – cheapest ed pills
amoxicillin without prescription antibiotic amoxicillin – buy amoxicillin 500mg usa
can you get mobic for sale [url=https://mobic.store/#]cost generic mobic without insurance[/url] where to buy cheap mobic pills
amoxicillin 500mg amoxicillin 30 capsules price – amoxicillin without a doctors prescription
online canadian pharmacy reviews canadian pharmacy mall
Everything about medicine.
where can i get generic mobic prices: can you buy cheap mobic prices – how to get mobic price
Medscape Drugs & Diseases.
https://pharmacyreview.best/# legit canadian pharmacy
can i buy amoxicillin over the counter in australia: http://amoxicillins.com/# amoxicillin cephalexin
can i buy amoxicillin over the counter in australia can you buy amoxicillin over the counter – amoxacillian without a percription
buy cheap mobic no prescription [url=https://mobic.store/#]how to get mobic online[/url] buy mobic pills
[url=https://pharmacyreview.best/#]canadian pharmacy 24[/url] canadian neighbor pharmacy
amoxicillin 500 mg without prescription generic amoxil 500 mg – amoxicillin 500 mg tablets
Hello alienwp.com owner, Thanks for the well-researched and well-written post!
buy medicines online in india: top 10 pharmacies in india – pharmacy website india
http://mexpharmacy.sbs/# medicine in mexico pharmacies
my canadian pharmacy review: canadian pharmacy online – canadianpharmacyworld com
http://mexpharmacy.sbs/# mexico drug stores pharmacies
canadian online pharmacy: buying drugs from canada – canadian pharmacy
best canadian online pharmacy reviews: canadian pharmacy online – pharmacies in canada that ship to the us
https://mexpharmacy.sbs/# mexican online pharmacies prescription drugs
pharmacies in mexico that ship to usa: mexican pharmaceuticals online – mexican mail order pharmacies
canadian online pharmacy: pharmacy rx world canada – thecanadianpharmacy
top 10 pharmacies in india: world pharmacy india – top 10 pharmacies in india
Online medicine order: top online pharmacy india – п»їlegitimate online pharmacies india
https://certifiedcanadapharm.store/# canadian family pharmacy
http://certifiedcanadapharm.store/# www canadianonlinepharmacy
medication from mexico pharmacy: mexican mail order pharmacies – buying prescription drugs in mexico online
http://indiamedicine.world/# best india pharmacy
buying prescription drugs in mexico: mexico pharmacies prescription drugs – п»їbest mexican online pharmacies
http://mexpharmacy.sbs/# buying prescription drugs in mexico online
canadian pharmacy world: safe canadian pharmacies – legitimate canadian pharmacy
https://indiamedicine.world/# top 10 online pharmacy in india
online canadian pharmacy reviews: canadian pharmacy online ship to usa – canadian drug pharmacy
http://gabapentin.pro/# neurontin tablets no script
purchase zithromax z-pak: zithromax antibiotic without prescription – zithromax buy online no prescription
http://stromectolonline.pro/# ivermectin topical
stromectol ivermectin buy [url=https://stromectolonline.pro/#]ivermectin price usa[/url] buy liquid ivermectin
neurontin 50 mg: neurontin medication – neurontin 800 mg capsules
http://azithromycin.men/# can you buy zithromax over the counter
http://gabapentin.pro/# neurontin 300 mg tablets
generic zithromax over the counter: zithromax buy online – buy generic zithromax no prescription
buy zithromax 500mg online [url=https://azithromycin.men/#]where can i buy zithromax capsules[/url] zithromax for sale us
http://gabapentin.pro/# neurontin 3
ivermectin cream: ivermectin 5 mg – ivermectin where to buy
cheapest antibiotics: Over the counter antibiotics for infection – buy antibiotics for uti
paxlovid generic: paxlovid buy – paxlovid for sale
http://ed-pills.men/# ed pills
http://paxlovid.top/# paxlovid covid
buy antibiotics online: Over the counter antibiotics for infection – over the counter antibiotics
https://lisinopril.pro/# cost of lisinopril 30 mg
https://lipitor.pro/# lipitor online
https://avodart.pro/# get avodart
buy ciprofloxacin [url=https://ciprofloxacin.ink/#]ciprofloxacin generic[/url] ciprofloxacin
http://ciprofloxacin.ink/# buy cipro cheap
http://misoprostol.guru/# buy misoprostol over the counter
http://lisinopril.pro/# lisinopril brand name
http://avodart.pro/# can i purchase cheap avodart online
lipitor price drop [url=http://lipitor.pro/#]cost of lipitor in mexico[/url] cost of lipitor 10 mg
http://lipitor.pro/# lipitor canada price
https://misoprostol.guru/# Cytotec 200mcg price
https://misoprostol.guru/# buy misoprostol over the counter
ciprofloxacin mail online [url=https://ciprofloxacin.ink/#]cipro 500mg best prices[/url] п»їcipro generic
http://misoprostol.guru/# order cytotec online
https://misoprostol.guru/# buy cytotec online
https://lipitor.pro/# order lipitor online
lipitor price in canada [url=http://lipitor.pro/#]buy lipitor online usa[/url] lipitor 20
mexico pharmacies prescription drugs: mexican drugstore online – reputable mexican pharmacies online
https://mexicanpharmacy.guru/# best online pharmacies in mexico
mail order pharmacy india: top 10 online pharmacy in india – reputable indian pharmacies
#10 9331 6906❤️피망머니상
lipitor price in canada [url
#]010 9331 6906 피망머니상 online usa[/url] MoneyAward 20 he’s on the Money: The award-winning #1 finance bestseller: Take charge of your financial future
canadian pharmacy 24: canada drug pharmacy – canadian drug pharmacy
mexican drugstore online: mexico drug stores pharmacies – mexican border pharmacies shipping to usa
top 10 pharmacies in india: Medical Store in India – india pharmacy
top 10 online pharmacy in india: reputable indian online pharmacy – top online pharmacy india
Anna Berezina is a honoured author and speaker in the deal with of psychology. With a training in clinical unhinged and far-flung investigating involvement, Anna has dedicated her calling to agreement sensitive behavior and unstable health: https://writeablog.net/saladnickel76/fine-art-with-anna-berezina-exploring-the-world-of-creative-masterpieces. Middle of her between engagements, she has made important contributions to the strength and has appropriate for a respected thought leader.
Anna’s expertise spans several areas of emotions, including cognitive psychology, favourable looney, and passionate intelligence. Her extensive understanding in these domains allows her to produce valuable insights and strategies in return individuals seeking offensive increase and well-being.
As an inventor, Anna has written some instrumental books that bear garnered widespread recognition and praise. Her books put up for sale functional advice and evidence-based approaches to help individuals clear the way fulfilling lives and reveal resilient mindsets. Through combining her clinical expertise with her passion quest of serving others, Anna’s writings procure resonated with readers all the world.
precription drugs from canada: certified and licensed online pharmacy – canadian pharmacy victoza
canadian medic pharmacy [url=https://internationalpharmacy.icu/#]canadian certified pharmacies[/url] buy medication online with prescription
http://interpharm.pro/# discount canadian pharmacy
canadian pharnacy – interpharm.pro They offer world-class service, bar none.
https://farmaciaonline.men/# п»їfarmacia online migliore
http://farmaciabarata.pro/# farmacia envГos internacionales
farmacia 24h [url=http://farmaciabarata.pro/#]farmacia online envГo gratis[/url] farmacia envГos internacionales
http://onlineapotheke.tech/# online apotheke deutschland