Did you just try to access your WordPress site only to be met by a scary message saying Error establishing a database connection instead of your WordPress site?
The Error establishing a database connection WordPress error is a somewhat common error that routinely pops up after changing hosts or migrating a WordPress site, though you might see it in other situations, too.
It can be scary because it seems like your site has completely disappeared and all of your data is gone.
First – don’t worry. Even though things look bad now, all of your site’s data should be safe and secure in the database. We’ll talk about this more in a second, but the issue here is that your WordPress site isn’t able to access your data, not that the data doesn’t exist.
Second, there are some troubleshooting steps that you can take to quickly fix the issue and get your site working again. So you should be able to fix the problem with minimal effort.
In this post, we’ll do two things:
First, we’ll explain a little more about what the Error establishing a database connection WordPress error means and why you might be seeing it.
Second, we’ll show you how to fix the WordPress Error establishing a database connection message for good. The exact troubleshooting steps that you’ll need to take often depend on when you’re encountering the message, so we’ll share different troubleshooting steps for two scenarios:
- Seeing this error on a newly created site or right after migrating a site.
- Seeing this error on an existing site where you didn’t change anything.
By the end, you should have a fully working WordPress site again!
What Does “Error Establishing a Database Connection” mean?
The Error establishing a database connection error message should look something like this on your WordPress site:
To help you understand what this error message means, we first need to break down WordPress into its two fundamental components.
There are roughly two parts to your WordPress site:
- Your files – these are your site’s PHP and HTML files, your CSS stylesheets, your JavaScript scripts, and so on.
- Your data – this your blog post content, your site settings, your users, your comments, and so on.
All of your site’s files sit on your server, but all of your site’s data lives in the database (hence the name).
If your site’s files can’t “talk” to the database, your site has no way of accessing all of the content, settings, and so on that it needs to render your site to visitors.
Because it’s impossible to display your site without accessing the database, your WordPress site will display the Error establishing a database connection message instead.
What can cause your site to have issues with connecting to the database? Well, we’re going to dig into that in detail in the troubleshooting steps in the next section, but some of the most common issues are the following:
- Incorrect database credentials – just like you need a username/password to log into your WordPress dashboard, your site needs a username/password to connect to the database. If these credentials are wrong (or if the database name is wrong), that will trigger the error. This issue can happen a lot when you migrate a site to a new host.
- Unresponsive database server – The server where your database lives could down, which is an issue with your hosting rather than your WordPress site.
- A corrupted database – Bad plugins, add-ons, themes, and data-transfer interruptions might leave your database short of tables or completely corrupted at worst. Thankfully, WordPress includes its own database repair tool.
- Corrupted WordPress files – issues with core WordPress files can also cause this error in fringe situations. The fix is to re-upload a clean copy of the core WordPress software.
In the next section, we’ll outline the most common solutions that are known to work.
How to Fix Error Establishing a Database Connection in WordPress
There are two high-level situations when you might see the Error establishing a database connection message in WordPress:
- After migrating a site to a new host/server or trying to create a brand new WordPress install.
- On an existing site where you haven’t made any recent changes.
These situations typically have different fixes, so we’re going to divide them into different sections. You can click the links above to jump straight to the specific section with your scenario.
With that being said, this can be a tricky error. So if the tips in one section don’t work, we recommend also trying the tips in the other section. Basically, we’re just trying to direct you to the troubleshooting steps that are most likely to fix your specific situation so that you don’t waste time.
1. Error Message After Migrating a Site or Creating a New Site
If you see the Error establishing a database connection message after migrating your WordPress site to a new host or creating a brand new WordPress site, the problem is almost always incorrect database credentials.
In order for your WordPress site to connect to the database, it needs to know the following information about the database:
- Database name
- Database user username
- Database user password
- Database location
When you migrate a site, sometimes the database credentials at the new host can be different than they were at the old host, which will trigger the error.
Here’s how you can fix that.
Check Your Database Login Credentials
To begin, you’ll want to find out which WordPress credentials your WordPress site is configured to use.
To do this, you’ll need to access your site’s wp-config.php
file, which you can do by connecting to your server via FTP or using something like cPanel File Manager or your host’s file manager tool.
The wp-config.php
file should be located in your site’s root folder. Open the file and look for the following lines of code:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name');
/** MySQL database username */
define('DB_USER', 'database_user');
/** MySQL database password */
define('DB_PASSWORD', 'database_password');
/** MySQL hostname */
define('DB_HOST', 'localhost');
The details in the second pair of parentheses, where we have ‘database_name’, ‘database_user’ etc, will not appear as shown in the code above. These details are specific to your website and host.
The four lines simply mean:
'database_name'
– The name of your database goes here e.g. ‘wordpress_vista’'database_user'
– Your database username goes here e.g. ‘wordpress_new’'database_password'
– This is where you put the password for your database user e.g. ‘test!@#!@#’'localhost'
– This is where you input your database host. The default is ‘localhost’ for most web hosts.
If any one of these four credentials are incorrect, you will get the Error establishing a database connection message.
At this juncture, what you need to do is counter-check these credentials against those stored in your database.
Check the Database Name
First, let’s check if you have the correct database name in your wp-config.php
. Complete the following steps:
To get started, open phpMyAdmin. In most hosting accounts such as HostGator, GoDaddy, and Bluehost, phpMyAdmin is usually located under the Databases or Database Tools tab in cPanel or something similar:
Your host should automatically log you into phpMyAdmin. Or, you might be prompted for a login screen in rare cases.
Once you’re logged into phpMyAdmin, click on the Databases tab to query a list of your databases. From the list of databases, can you see the database that appears after DB_NAME
in your wp-config.php
file?
If you can see it, you’re golden – the problem does not lie in the database name. If you can’t see the database in phpMyAdmin, you need to contact your WordPress hosting provider, as the problem might be their server.
If the database doesn’t exist, you will need to restore one from backup (if you have a backup in place) or create a new one. See why it’s super-important to back up your WordPress site?
Let’s assume you’ve found your database and you have the correct name in wp-config.php. Now, let us check whether your database username, password, and host are correct.
Check Your Database Username and Password
Checking your username and password involves a little work. You need to create a .php
file and store it in your WordPress root folder. This is the same folder where you found the wp-config.php
file. Create a new .php
file, and name it check.php
or whatever you want.
You can create the file using FTP or via something like cPanel File Manager:
Once you create the file, it should appear in your root folder in a moment. Right click on it and choose Code Edit, or select it and click Code Editor on the menu. This should lead you to a blank page. Add the following code:
<?php
$link = mysql_connect('localhost', 'root', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
Be sure to replace 'localhost'
– 'root'
– and 'password'
with the database host (this will almost always be the default, localhost), username, and password in wp-config.php
respectively. Save the changes and go to the following URL in your web browser – yoursite.com/check.php
.
Make sure to replace yoursite.com
with your actual domain name.
If you see the message, “Connected successfully”, your login details are correct.
If you see “Could not connect: Access denied for user ‘yourusername’@’localhost’ (using password: yourpassword)” or some other error, your database host, username, or password is the culprit here.
If your login details are not working, you need to create new ones and then update your wp-config.php
with the new details.
Oftentimes, the easiest option here is to just:
- Create a new database user.
- Assign that user to your WordPress site’s database.
- Update your
wp-config.php
file to use that new database user.
Aside: Your problem could be as a result of the last credential, DB_HOST. By default, most web hosts use ‘localhost’, but you can try changing this to an IP address or URL as per your web host. You can get a list of hosts and their DB_HOST values on the WordPress Codex. If your host is not on the list, please contact them for this information.
Moving on, let’s create a new user.
Create New Database User and Password
Go back to your cPanel and access MySQL Databases. It is also located under database tools, the same tab you found phpMyAdmin:
Clicking on MySQL Databases should open something like this:
Once the MySQL Databases screen loads, navigate down to where you have MySQL Users. Under this, you will notice Add New User:
Enter a new username and password, and click Create User. Keep note of these details for your wp-config.php
file.
Note: Your setup could be different, but the procedure is much the same.
Once you create the new user, you need to assign the user to your WordPress database. This is the database that is shown after DB_NAME
in your wp-config.php
file.
To assign the user to your database, go to the MySQL Databases screen once again, and scroll down to where you will see Add User to Database:
Select the user you just created and your database, and click Add. On the next screen, make sure to give the database user all privileges and save those changes:
Now, go back to wp-config.php
and update the file with the new username and password information.
Make sure there are no spaces between the quotes. For example, ' your-username '
is bad, but 'your-username'
is great. Also, use single quotes as opposed to double quotes. Save all changes you’ve made to your wp-config.php
.
Now, try accessing your website. If everything went well, it should be working again.
Are you still getting the error? If that’s a yes, you can try the other fixes as well.
2. Error Message On an Existing Site That You Haven’t Migrated
If you see the Error establishing a database connection message on an existing site where you haven’t made any big changes recently (like migrating to a new host), it can be a little trickier to troubleshoot the problem. However, there are still some steps that you can take.
Make Sure Your Host Isn’t Experiencing Any Issues
Before you dig too deeply into troubleshooting your site, you’ll first want to make sure that the problem isn’t caused by your web host.
Some web hosts configure their environments in such a way that your site’s database server is separate from the file server. In these configurations, it’s possible for the database server to be down but the file server to still be functioning. When that happens, you’ll see the Error establishing a database connection message.
A good host should be monitoring for this and quickly fix the problem. However, it’s worth sending a quick message to support or checking your host’s uptime status just to rule out any issues on their end.
Check for Corrupted Database (and Repair If Needed)
Another problem that can suddenly affect a WordPress site is a corrupted database. Thankfully, it’s pretty easy to test if this is the case.
To test, try to open up your site’s backend admin dashboard.
If your backend dashboard loads fine but the frontend of your site shows the Error establishing a database connection message, you might have a corrupted database.
Or, you also might see a different message like “One or more database tables are unavailable” in the backend, which is another sign of a corrupted database.
On the other hand, if you see the exact same Error establishing a database connection message in both the backend and the frontend, this is not the issue and it’s pointless to continue with this step. Instead, just skip ahead to the next step.
So – how can you fix a corrupted WordPress database?
Thankfully, WordPress includes its own tool to do this – all you need to do is enable it. Here’s the quick version for enabling the WordPress database repair tool – we’ll show you more detailed instructions below:
- Access your server’s files by connecting via FTP or using cPanel File Manager (or your host’s custom file manager tool if applicable).
- Edit the
wp-config.php
file. - Add the following code snippet –
define ( 'WP_ALLOW_REPAIR' , true);
- Visit
yoursite.com/wp-admin/maint/repair.php
in your browser, making sure to replaceyoursite.com
with your actual domain name. - Run the database repair tool by clicking Repair Database.
- Once the database repair tool finishes, remove the code snippet that you added to the
wp-config.php
file.
Here’s what it looks like to add the code snippet to your wp-config.php
file – add it above the line that says “/* That’s all, stop editing! Happy publishing. */”
define ( 'WP_ALLOW_REPAIR' , true);
Once you’ve done that, you can go to yoursite.com/wp-admin/maint/repair.php
to launch the database repair tool. Click the Repair Database button to start the process and WordPress will handle the rest:
Once the database repair process finishes, your site should hopefully start working again.
If it does, make sure to go back to your wp-config.php
file and remove the code snippet that you added earlier. With this code snippet added, anyone can access the database repair tool, even if they’re not logged in to WordPress.
You don’t want that, which is why it’s disabled by default and why you need to make sure to disable it again when you’re finished.
Re-Upload a Clean Copy of WordPress to Fix Corrupted Files
In addition to a corrupted database, another common cause of the Error establishing a database connection message can be corrupted core WordPress files.
Diagnosing the specific problem is tricky, but you’ll find lots of situations where some weird tweak in a certain file is causing problems.
Thankfully, you don’t have to find the specific error. Instead, you can just re-upload a clean copy of the core WordPress software to make sure that all of your core files are exactly how they should be.
Don’t worry – re-uploading the core WordPress software will not overwrite any of your data. It’s basically just reinstalling the WordPress software, which is the same process your site undergoes every time you update WordPress.
However, because you probably can’t access your WordPress dashboard, you’ll need to do this via FTP.
To start, do the following:
- Go to the WordPress download page at WordPress.org
- Download the latest version of WordPress – it should be a single zip file that’s around 15 MB
- Once the download completes, extract the zip file on your computer
Now, you should have a folder that contains all of the core WordPress software.
Open this folder and delete the following files/folders:
wp-content
folderwp-config-sample.php
filewp-config.php
file – this file shouldn’t actually be there, but if you do see it for some reason make sure to delete it.
Once you’ve prepped the clean copy of WordPress by deleting those files/folders, you’re ready to upload it to your site:
- Connect to your WordPress site’s server using FTP
- Upload all of the remaining WordPress files/folders to your root folder. You want everything to match up so that the new files are getting uploaded to the same location as the existing files.
- When your FTP program asks you what to do about duplicate files, tell it to overwrite all files with the new version. If you don’t see a warning about duplicate files, make sure that you’re uploading the new files to the correct location. You want to overwrite all the existing core WordPress files on your server.
Once the upload finishes, you should have a clean copy of all your core WordPress files and that will hopefully fix the Error establishing a database connection message.
Nothing Working? Try Restoring a Recent Backup
If nothing has worked so far, your best bet might be to just try restoring your site from your most recent backup.
If you or your host take regular backups of your site, you should be able to restore your site to working condition with little to no data loss.
WordPress Error Establishing a Database Connection FAQs
To finish out this post, let’s go over some common questions you might have about the Error establishing a database connection WordPress problem.
If WordPress isn’t recognizing your database, you’ll first want to make sure that the database name, user, and password are set properly in your site’s wp-config.php file.
If you have the correct credentials, another problem could be that the database user doesn’t have full permission to access the database. Make sure that you attached the database user to the database in cPanel.
If the Error establishing a database connection message is intermittent (i.e. it comes and goes), you can be confident that the problem is not incorrect database credentials. Instead, it’s likely that your database hosting server is being overwhelmed and failing during high-load periods.
You can consider reaching out to your host for help or upgrading to more powerful WordPress hosting.
To fix your corrupted database, you can try using WordPress’s built-in database repair tool. You’ll need to activate this tool in your site’s wp-config.php file. Then, you can launch the repair tool by going to yoursite.com/wp-admin/maint/repair.php
.
To test your WordPress database connection, you can upload a simple PHP file with a short code snippet to your site. We show you how to do it at the beginning of the troubleshooting steps in this post.
If you started seeing the Error establishing a database connection WordPress message after migrating your site, the problem is almost certainly an issue with the database name, username, or password that are defined in your site’s wp-config.php file. Make sure that all of these details are correct for the new host and also that the database user has full permission to access the database.
Fix This WordPress Error Today
The WordPress Error establishing a database connection error can be frustrating. However, in almost all situations, your site’s data is still there, you just need to find a way to fix the connection so that WordPress can access the database again.
In this post, we’ve shared some troubleshooting tips to help you solve the problem.
If you recently migrated your site or created a fresh WordPress install, it’s probably an issue with your site’s database credentials. If not, try the other solutions to fix the problem.
We hope this article helped you learn how to fix the “Error Establishing a Database Connection” error in WordPress. For some other tips on troubleshooting WordPress, you may also want to see our article on how WordPress beginners can dodge these 7 common mistakes.
Now you…
Have you experienced and resolved this error before? What caused it, and how did you solve it? Please share your tips and solutions with us, and make this post more resourceful. Thanks in advance!
Alex says
Thanks for this guide, it really saved me!
Freddy Muriuki says
Awesome! Glad it was useful 🙂
Kakaire Charles says
Hullo Alex. I was saved too.
Rakesh says
You made my day. Thanks a lot mate
Freddy Muriuki says
Glad you loved the post Rakesh. Thank for contributing!
Mitch Mitchell says
Very nicely done, very detailed and logically set. I’ve had this issue a few times and every time I’ve been able to figure it out but it’s taken time because I’d never written down the process. I certainly should have though, but I’m glad you did. Great job!
Freddy Muriuki says
Thank you Mitch. Such a great and inspirational comment deserves a gold medal. Thanks for the compliment and passing by 🙂
Rob says
Thank you for sharing this great guideline. It is really helpful for me.
Uplifting Families says
Just keep in mind that it can be a hosting issue as well. If the host computer can’t talk to your site/database you will get this error too. We learned this on Black Friday, two years ago. The host server was running out of memory.
Devesh Sharma says
Thanks for the tip, Christy :).
Lily says
I notice that mine would do the same on some occasions and would fix itself after a few minutes. I wonder what that is all about! Its great to know that you can fix such issues. Great post Freddy!
Akpan Promise says
I am guessing the site is on shared hosting.
If it does that often then increase php memory limit from 64 to 128 or even as high as 256.
You can also increase WP Memory limit too.
Other than that, you’ve got no issues.
Cat says
I’m getting this error quite frequently – same message on front and back end, and no issues with credentials etc. It seems to happen regularly when I’m adding a lot of posts to my site. I’m hosting on a dedicated server, and when I look at the service monitor in Direct Admin I can see over 100 ID’s listed under mysqld – which is a little bit odd because it happens at times of the day when I’m not getting a whole lot of traffic. If I stop MySQL and restart it, the problem goes away, and the number of ID’s in the service monitor generally drops down to about a dozen. If I wait about half an hour the problem also goes away. It makes me wonder if WordPress is somehow establishing connections but then failing to let them go in a timely manner when it’s done with them or something like that. Thoughts?
Freddy says
Hey Cat,
You might want to check with your web host, as you might have memory throttling issues. If you’re operating with insufficient memory on your server, you’re like to experience this error. Let us know how it goes, and thanks for passing by 🙂
Nifras says
hi there
frequantly i m getting this error message 5-10 min
“Error establishing a database connection” after then working nice my website load fast i m using little bit plugin also why i m getting this error message frequantly please help me
i m using godaddy deluxe wordpress hosting plan
godaddy customer care very poor
Freddy Muriuki says
Hey Nifras
Thanks for posting your comment. Which plugin are you using? I have experienced this problem myself, and I resolved it by removing the problematic plugin. Let me know. Thanks once again for passing by, your comments are highly appreciated.
Ryan says
I am facing the same problem since two weeks. I read all of it and tried.
What I did is I tried to restart my apache web server, but the command failed, then I tried to restart my mysql server , this command also failed and then I tried to login to mysql but it also failed. I couldn’t understand what was happening. I tried these commands thrice and on the third time the mysql restart command worked and the mysql server restarted. After that the error went away and the site started functioning normally.
The problem I am facing right now is that this thing is happening after every 3 to 4 days. After evry 3 to 4 days I am getting the same error when I check my site.
How to remove it permanently ? NEED HELP !
There is no problem with login credentials as I remember them very well.
I am using Amazon AWS EC2 with uBuntu.
Freddy Muriuki says
Hey Ryan,
Thank for you passing by. I am sorry you’re facing this problem. You will need to contact your web host seeing that the problem keeps recurring. Something could be amiss with your server configuration. Please respond with more details about the error (for instance: did you make any changes i.e. install a plugin, add-on, theme, changed code etc when the error started?) We will be glad to look further into it and help 🙂 Cheers
Tony Franco says
Hello Ryan,
Please, i´m getting the same problem on my ec2 aws, several times a day…
All credentials ok, database ok (was well optimized these days ago).
Service comes back only when restart mysqld service…
Did you solve your problem?
Thanks and Regards,
Tony Franco
Shaikh Riyaz says
I am having the same problem. Did you found the solution?
Tony Franco says
Hello Shaikh,
I´m sorry because i don´t remember how i fixed it.. that time a lot of things were giving errors… now i´m not at aws anymore…
Hope you find the solution!
Regards,
Tony
Brendan Ford says
Hi Freddy
Thanks for the detailed steps to fix this. Unfortunately I didn’t get the same results you described.
When I go to “/wp-admin/” I get an EEDC, but it is not the same look or page if I go to the WP index.php. The admin one gives me many more options under the EEDC, telling me the info in the config file is bad.
Then I went to cpanel and did a DB check and the web hosting site said all was good.
Then I created the check.php file as you suggested and it didn’t tell me i succeeded or failed instead in just displayed the entire code in the file.
I have not tried the step you talked about repairing the DB.
Any suggestions as to what I should do next?
Dev says
Hey Brendan,
Sorry to hear about problem. I think the best option is to contact your host and explain the situation, as I cannot pinpoint the exact issue.
If you can share the screenshots & site url, I may be able to give you a better answer.
Brendan Ford says
Hi Dev Thanks for your interest in trying to fix this
Here are the Screen shots, sorry you didn’t get them the first time I sent them
[cid:image001.png@01D1AEE8.71CD9840]
[cid:image002.png@01D1AEE8.71CD9840]
[cid:image003.png@01D1AEE8.E42F8420]
[cid:image004.png@01D1B06F.D9FF9840]
Brendan Ford says
Here are some screen shots of what I was talking about.
[cid:image001.png@01D1AEE8.71CD9840]
[cid:image002.png@01D1AEE8.71CD9840]
[cid:image003.png@01D1AEE8.E42F8420]
Thanks for your help
Melissa says
Bless your heart! Im soooo not a developer and did something tonight that ruin my WP config file. Actually it was WP super cache. Took my whole site. But i got it back it up thanks to you! Thnk you!!!!
Dev says
Glad we could be of help, Melissa. Thanks for the nice words :).
Thevendran says
pls i need help
i can’t connect to my website or database
I’ve tried all the instructions above and it still doesn’t work
i want to try the last option
can some pls help me and instruct me on hoe to back up my wordpress site and database pls
Dev says
Hey there!
Sorry for the late reply, you can use the Duplicator plugin to backup your site, here’s a step by step tutorial — https://www.wpkube.com/move-backup-website-wordpress-duplicator-plugin/
Here are a few more backup plugins to choose from — https://www.wpkube.com/wordpress-backup-plugins/
Let me know how it goes.
Mr K says
I had this error. turns out that MYSql was crashing due to a lack of memory. worth checking the mysqld.log file to see if it has issues allocating memory for the buffer.
1gb free tier amazon probably not up to the job, understand apache eats memory. 2 options. upgrade the server to 2gb or create a seperate DB server. I have tried the former for now
Dev says
Hey K, thanks for sharing your experience, really useful for others struggling with the same issue.
mennah says
i’ve created and edited the check.php file , but when i open it , it just views a page with the code and my credentials , don’t know is it good or what ? please tell me !
THANKS a lot for the very helpful post !
Dev says
Hey Mennah,
You need to navigate to http://yoursite.com/check.php. If you get “Connected successfully”, your login details are correct. Meaning username & password are not the issue here.
Jone says
I have been getting this error for a day now. Had tried severally to upload the demo content of a theme to my site, when i failed, I contacted the authors and they imported and installed the demo. Thereafter, I have encountered the EEDC. When I log in to http://www.mywebsite.com/wp my site opens. But when i attempt to go to my site http://www.mywebsite.com, I get the error. If i also attempt to log on to the backend of my wordpress, I get the same error with more additional message “Database tables are missing”.Have checked my credentials and they are correct. tried repairing my database and it would return the same error. Please what do I do ?
do i create a new table for the tables that appear missing and how ?
Jared says
This was very useful and helped me fix a website problem. Thank you so much!
Bill says
I have my site hosted on Amazon cloud in a single instance Ubuntu server hosting both wordpress and mysql. I solved this by rebooting the server. Would like to know the cause, though.
Firoz Ahmed says
Very helpful post. Thanks for sharing….
Kakaire Charles says
Hello, I desperately need help. I have tried all with a lot of care but I have failed to fix the Error establishing a database connection error. What else can I do?
Kakaire Charles says
Adding a new user worked for me very very well. Thanks a lot Freddie. i am very happy.
Freddy Muriuki says
That’s it 🙂 Thank you for passing by Kakaire, and finding a moment to share with us. Hope all is well.
Talal says
Hi, I am having some issues in uploading WordPress site on GoDaddy. So, I need your support email to resolve and discuss the issue. I am in trouble and need to fix the issue as soon as possible… Kindly help me out. There is not any option of live chat or email support, so, I am stuck now
Your help will be highly appreciated.
Thanks
Abanoub says
Hi bro!
To fix this problem tried those fixes, and every time one fixes it :
1. Open wp-config.php, check line DB_USER, DB_PASSWORD, DB_HOST, DB_NAME. Make sure the values is same with mysql access.
2. If you use Dedicated server or VPS hosting, try to restart your mysql server by typing :
-service mysql restart
or
-service mysql start
but if you use shared hosting, ignore this step!
3. if all the previous fixes can not fix it, so it’s a server-side problem! it is not your error! so let the hosting company fix this error for you because it is their error!
contact them or give them a day or so and they will solve this error and the problem will disappear automatically.
Vincent says
Thanks so much for this guide! Very clear every step of the way!
The step of creating new user credentials did the trick!
Blessings! 🙂
Freddy Muriuki says
Awesome! Glad the post was useful. It’s such a honor.
John says
I had the this problem too, I tried the first option of adding define ( ‘WP_ALLOW_REPAIR’ , true); in wp-config.php file. it didnt work and the error was still there. I tried logging in to my database and got another error #2002 Cannot log in to the MySQL server.
At this point i had to contact my the tech department of my host provider. I dont know if they did anything but later i was able to click on Mysql database from the cpanel dashboard instaed of PhpMyAdmin. there and then i got the option of either to repair or view my database. i clicked on repair and voom my site was restored
Freddy Muriuki says
Hey John, Glad you resolved that. Thank you a bunch for your valued contribution 🙂
Mansoor says
In addition to this problem I was unable to access any of the database in mysql neither phpmyadmin. What to do in that case?
I tried adding new user but still there was the same problem
Helen Rouse says
Hello, can you help? The link http://www.yoursite.com/wp-admin/maint/repair.php. doesn’t take me to the page as described. Is there an update to the link that I don’t know about?
Cj says
Thank you so much!!!
I am so relived right now. This morning I tried to log into my site and suddenly I’m getting errors. After reading up a lot and struggling, I finally sorted it out thanks to your post. Really appreciate it!
Cj
Ben says
Thanks so much for this guide. It helped me get my site back online.
CRBCI says
USEFUL POST. I REALLY FOUND IT HELP. TRIED IT AND IT WORKED
Mo says
You are a life saver buddy!
Worked for me after struggling for so long with the database!
Brian Hickling says
I am a user of iconsetc wordpress site which was working fine till last week I became a paid member of the site (with the promise of over 300,000 extra icons). But I can no longer access site from any system getting an “Error establishing database connection” message each time. Even the email to the site gives the same message. Cannot even access the free stuff anymore so its their database that has gone corrupt. I feel I have been cheated out of of a 70 dollar fee because it seems they have no intention of fixing the problem if they even know they have one! The site is an old one and my guess is nobody administrates it anymore but it still sells membership. I am a systems engineer and could solve this problem with your advice on this page but since I’m only a user not the site (database) owner I can do nothing!
Rose says
This is such a beautifully clear, step-by-step guide. Thanks for making such an effort!
Sukhdev says
So So So So Helpful…..!!!!! Not even the hosting websites could provide this solution. Thanks to this post I could sort out shifting a wordpress database from hostgator to godaddy. Word of caution, Godaddy has the worst customer help/support out there, hostgator was so much better and technically sound. Thank you for this post and God Bless….!!!!
Yelutide says
I can’t but to come back to say Thank You. The article fixed it for me. Thank you so much for this post Admin.
Megacon Beton says
the most annoying error of all is maybe 500 internal server error, you never know when it hits you and frustrate the hell out of me to fix.
Dave says
Thank you. This fixed my site.
nitin says
thank you it worked for me… i also wanted to know how to prevent this error in future is it a hosting problem or what , why this error exists.
pls let us know. yor r doing a great work.
Love nitin
Okeem mcbean says
Why I’m having this issue that is established by the connection
Brian says
Well done. I created a new user and password and connected it to the same database and it resolved the issue after adding the new user/pass to the wp-config.php file. Thanks for the thoughtful post that helped me resolve the issue.
Imtiaz says
Hi,
I have changed the admin password through phpmyadmin but the site says database eror.I just changed the admin password, can someone help
anthony says
Thank You Thank You Saved my sanity
Amar Vijay says
Hi,
The link which you have mentioned is not working for my site. It is giving 404 error. Please help. I had replaced yoursite.com with my url.
ClemzyBoss says
Thanks you guys…y’all just got my mate and i screaming #WakandaForever with much joy
Zeena Kabad says
Hi,
Thanks alot for this article
My problem is when I install the theme and import its demo files this error occurs, it corrupts the wordpress database. I think that the database is overwritten. When I restore the origin database it works good.
Now how can I use the theme without corrupting my work, is it possible?
Thanks alot in advance
editorial-staff says
I’m assuming the theme you are using is a commercial theme, in which case you should contact the theme author for support about the issue.
Bill says
My problem solved when I rebuilt the LAMP server. The versions of software currently installed are php 7.2.10, Apache/2.4.29, mysql 5.7.24, ubuntu 18.04
Anoop negi says
thankuu so much brother…. now my site getting this “Error establishing a database connection” error.. and i found your helpful article.
Frizza Wold says
Thank you for sharing How to fix WordPress database connection.
It will really helpfull for the beginners who are facing the problem of error establishing in database connection. Also, they will easily get the result by following these steps.