• Categories
    • Tutorials
    • Beginners Guide
    • WordPress News
    • WordPress Security
    • Best WordPress Plugins
    • WordPress Themes
    • Product Reviews
    • WP Tips & Tricks
  • Guides
    • Start a Blog
    • Make a Website
    • WordPress Hosting
  • WordPress Hosting
    • A2 Hosting
    • HostGator
    • Bluehost
    • Cloudways
  • Managed Hosting
    • WPEngine
    • Rocket.net
    • WPX
    • Kinsta
  • Coupons
    • WPEngine
    • Flywheel
    • Cloudways
    • A2 Hosting
    • WPX Hosting
WordPress Tutorials

How to Fix Error Establishing a Database Connection in WordPress

Last Updated on: February 10, 2022 Colin Newcomer 70 Comments

How to Fix Error Establishing a Database Connection in WordPress

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:

  1. Seeing this error on a newly created site or right after migrating a site.
  2. 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:

Error establishing a database connection WordPress error message

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:

  1. Your files – these are your site’s PHP and HTML files, your CSS stylesheets, your JavaScript scripts, and so on.
  2. 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:

  1. After migrating a site to a new host/server or trying to create a brand new WordPress install.
  2. 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:

Open phpMyAdmin

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?

Check for database name
Example of what to expect.

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:

Create a new file

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:

  1. Create a new database user.
  2. Assign that user to your WordPress site’s database.
  3. 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:

Open database list

Clicking on MySQL Databases should open something like this:

Database interface

Once the MySQL Databases screen loads, navigate down to where you have MySQL Users. Under this, you will notice Add New User:

Create a new database 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:

Assign database 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:

Give database user all privileges to fix error establishing a database connection

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:

  1. Access your server’s files by connecting via FTP or using cPanel File Manager (or your host’s custom file manager tool if applicable).
  2. Edit the wp-config.php file.
  3. Add the following code snippet – define ( 'WP_ALLOW_REPAIR' , true);
  4. Visit yoursite.com/wp-admin/maint/repair.php in your browser, making sure to replace yoursite.com with your actual domain name.
  5. Run the database repair tool by clicking Repair Database.
  6. 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); 
Enabling WordPress database repair tool

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:

Using WordPress database repair tool

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:

  1. Go to the WordPress download page at WordPress.org
  2. Download the latest version of WordPress – it should be a single zip file that’s around 15 MB
  3. 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 folder
  • wp-config-sample.php file
  • wp-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:

  1. Connect to your WordPress site’s server using FTP
  2. 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.
  3. 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.

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!

+ Share
Disclosure

Colin Newcomer

Colin Newcomer is a WordPress writer for WPKube. He uses WordPress more often than any sane person should.

Related Posts

Back to all articles
  • WP Activity Log Review

    WP Activity Log Review: How to Secure Your Site and Log Activity

  • How to Stress Test WordPress Using a Free Tool (Full Guide)

  • How to Increase the Memory Limit in WordPress

    How to Increase the Memory Limit in WordPress

Coupons

View more deals
  • LearnDash Coupon Code!
    40% off

    LearnDash Coupon

    Searching for a LearnDash coupon to save on one of the top W
    Get This Deal
  • WP Activity Log Coupon
    20% OFF

    WP Activity Log Coupon

    Website security encompasses a whole host of elements, tasks, and
    Get This Deal
  • Recipe Card Blocks Coupon
    15% OFF

    Recipe Card Blocks Coupon

    Running a cooking or food website can be fun (and tasty) – but
    Get This Deal
70 Comments Leave a Reply
  1. Alex says

    June 9, 2015 at 5:22 pm

    Thanks for this guide, it really saved me!

    Reply
    • Freddy Muriuki says

      August 5, 2015 at 11:24 am

      Awesome! Glad it was useful 🙂

      Reply
    • Kakaire Charles says

      January 6, 2017 at 6:26 am

      Hullo Alex. I was saved too.

      Reply
  2. Rakesh says

    June 11, 2015 at 8:30 pm

    You made my day. Thanks a lot mate

    Reply
    • Freddy Muriuki says

      August 5, 2015 at 11:32 am

      Glad you loved the post Rakesh. Thank for contributing!

      Reply
  3. Mitch Mitchell says

    June 15, 2015 at 7:25 pm

    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!

    Reply
    • Freddy Muriuki says

      August 5, 2015 at 11:26 am

      Thank you Mitch. Such a great and inspirational comment deserves a gold medal. Thanks for the compliment and passing by 🙂

      Reply
  4. Rob says

    July 13, 2015 at 10:25 am

    Thank you for sharing this great guideline. It is really helpful for me.

    Reply
  5. Uplifting Families says

    August 20, 2015 at 9:57 am

    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.

    Reply
    • Devesh Sharma says

      August 21, 2015 at 5:28 am

      Thanks for the tip, Christy :).

      Reply
  6. Lily says

    November 15, 2015 at 11:34 pm

    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!

    Reply
    • Akpan Promise says

      April 18, 2016 at 6:26 am

      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.

      Reply
  7. Cat says

    March 3, 2016 at 3:59 am

    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?

    Reply
    • Freddy says

      April 13, 2016 at 1:11 pm

      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 🙂

      Reply
  8. Nifras says

    March 24, 2016 at 5:37 am

    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

    Reply
    • Freddy Muriuki says

      March 24, 2016 at 9:20 pm

      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.

      Reply
  9. Ryan says

    April 17, 2016 at 7:05 pm

    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.

    Reply
    • Freddy Muriuki says

      April 22, 2016 at 11:47 am

      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

      Reply
    • Tony Franco says

      May 26, 2016 at 11:36 pm

      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

      Reply
      • Shaikh Riyaz says

        April 22, 2017 at 4:58 am

        I am having the same problem. Did you found the solution?

        Reply
        • Tony Franco says

          April 24, 2017 at 12:21 pm

          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

          Reply
  10. Brendan Ford says

    May 15, 2016 at 9:20 pm

    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?

    Reply
    • Dev says

      May 17, 2016 at 3:31 pm

      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.

      Reply
      • Brendan Ford says

        May 18, 2016 at 12:11 am

        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]

        Reply
  11. Brendan Ford says

    May 16, 2016 at 1:32 am

    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

    Reply
  12. Melissa says

    August 29, 2016 at 1:23 am

    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!!!!

    Reply
    • Dev says

      August 30, 2016 at 2:58 am

      Glad we could be of help, Melissa. Thanks for the nice words :).

      Reply
  13. Thevendran says

    October 9, 2016 at 2:47 pm

    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

    Reply
    • Dev says

      October 13, 2016 at 3:03 am

      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.

      Reply
  14. Mr K says

    October 19, 2016 at 4:29 pm

    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

    Reply
    • Dev says

      October 24, 2016 at 2:37 pm

      Hey K, thanks for sharing your experience, really useful for others struggling with the same issue.

      Reply
  15. mennah says

    October 23, 2016 at 2:18 am

    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 !

    Reply
    • Dev says

      October 24, 2016 at 3:11 pm

      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.

      Reply
  16. Jone says

    October 26, 2016 at 7:34 am

    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 ?

    Reply
  17. Jared says

    November 4, 2016 at 6:36 pm

    This was very useful and helped me fix a website problem. Thank you so much!

    Reply
  18. Bill says

    December 13, 2016 at 4:55 pm

    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.

    Reply
  19. Firoz Ahmed says

    December 19, 2016 at 7:19 am

    Very helpful post. Thanks for sharing….

    Reply
  20. Kakaire Charles says

    January 5, 2017 at 8:07 am

    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?

    Reply
  21. Kakaire Charles says

    January 5, 2017 at 4:36 pm

    Adding a new user worked for me very very well. Thanks a lot Freddie. i am very happy.

    Reply
    • Freddy Muriuki says

      March 1, 2017 at 11:09 pm

      That’s it 🙂 Thank you for passing by Kakaire, and finding a moment to share with us. Hope all is well.

      Reply
  22. Talal says

    January 19, 2017 at 9:27 am

    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

    Reply
  23. Abanoub says

    January 27, 2017 at 7:10 am

    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.

    Reply
  24. Vincent says

    February 17, 2017 at 10:48 pm

    Thanks so much for this guide! Very clear every step of the way!

    The step of creating new user credentials did the trick!

    Blessings! 🙂

    Reply
    • Freddy Muriuki says

      March 1, 2017 at 11:07 pm

      Awesome! Glad the post was useful. It’s such a honor.

      Reply
  25. John says

    March 1, 2017 at 10:30 am

    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

    Reply
    • Freddy Muriuki says

      March 1, 2017 at 11:06 pm

      Hey John, Glad you resolved that. Thank you a bunch for your valued contribution 🙂

      Reply
  26. Mansoor says

    March 30, 2017 at 8:45 am

    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

    Reply
  27. Helen Rouse says

    April 25, 2017 at 1:27 pm

    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?

    Reply
  28. Cj says

    May 22, 2017 at 3:39 pm

    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

    Reply
  29. Ben says

    September 22, 2017 at 8:23 pm

    Thanks so much for this guide. It helped me get my site back online.

    Reply
  30. CRBCI says

    September 24, 2017 at 10:25 am

    USEFUL POST. I REALLY FOUND IT HELP. TRIED IT AND IT WORKED

    Reply
  31. Mo says

    March 2, 2018 at 6:42 am

    You are a life saver buddy!
    Worked for me after struggling for so long with the database!

    Reply
  32. Brian Hickling says

    March 4, 2018 at 8:18 pm

    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!

    Reply
  33. Rose says

    March 23, 2018 at 6:15 pm

    This is such a beautifully clear, step-by-step guide. Thanks for making such an effort!

    Reply
  34. Sukhdev says

    April 2, 2018 at 3:49 pm

    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….!!!!

    Reply
  35. Yelutide says

    May 14, 2018 at 11:38 am

    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.

    Reply
  36. Megacon Beton says

    May 24, 2018 at 6:47 am

    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.

    Reply
    • Dave says

      June 5, 2018 at 10:34 pm

      Thank you. This fixed my site.

      Reply
  37. nitin says

    May 30, 2018 at 1:59 pm

    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

    Reply
  38. Okeem mcbean says

    July 8, 2018 at 3:27 pm

    Why I’m having this issue that is established by the connection

    Reply
  39. Brian says

    July 26, 2018 at 10:52 pm

    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.

    Reply
  40. Imtiaz says

    August 6, 2018 at 10:30 am

    Hi,

    I have changed the admin password through phpmyadmin but the site says database eror.I just changed the admin password, can someone help

    Reply
  41. anthony says

    August 11, 2018 at 10:48 am

    Thank You Thank You Saved my sanity

    Reply
  42. Amar Vijay says

    August 20, 2018 at 7:07 am

    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.

    Reply
  43. ClemzyBoss says

    September 5, 2018 at 4:22 pm

    Thanks you guys…y’all just got my mate and i screaming #WakandaForever with much joy

    Reply
  44. Zeena Kabad says

    November 28, 2018 at 7:22 pm

    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

    Reply
    • editorial-staff says

      November 29, 2018 at 10:04 am

      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.

      Reply
  45. Bill says

    November 29, 2018 at 10:46 am

    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

    Reply
  46. Anoop negi says

    June 21, 2019 at 1:32 pm

    thankuu so much brother…. now my site getting this “Error establishing a database connection” error.. and i found your helpful article.

    Reply
  47. Frizza Wold says

    October 22, 2019 at 6:35 am

    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.

    Reply

Leave a Reply Cancel reply

Full Disclosure This post may contain affiliate links, meaning that if you click on one of the links and purchase an item, we may receive a commission (at no additional cost to you). All opinions are our own and we do not accept payments for positive reviews.

Our Newsletter

Get awesome content delivered straight to your inbox.

Thank you!

You have successfully joined our subscriber list.

.

THE BEST OF WPKUBE

Some of the best content we have published so far.

BEGINNER GUIDES & REVIEWS

18 Best Cheap WordPress Hosting Providers in 2023 (From $1.99)
210 Best WordPress Hosting Options for 2023 (Pros & Cons)
38 Best Managed WordPress Hosting Providers for 2023 Compared
45 Best WooCommerce Hosting Providers Compared in 2023 (All Budgets)
5Top 9 Landing Page Plugins for WordPress (2023)
69 Best List Building Plugins for WordPress In 2023
7How to Fix the 500 Internal Server Error on Your WordPress Website
8Thrive Themes Review: A Look At The Full Membership
9Beaver Builder Review: Is it The Best Page Builder Plugin for WordPress (2023)?
10OptimizePress Review: Create Landing Pages with Ease
11How to Make a Website: Complete Beginner’s Guide
12Top 22 Best Free Stock Photo Resources For Your Site
1317 of the Best Google Fonts for 2023 (And How to Use Them in WordPress)
14How to Start a Blog in 2022 (Step by Step Guide)
15How To Fix ‘503 Service Unavailable’ WordPress Error
1611 Best Contact Form Plugins for WordPress in 2023
17How to Add a Custom Logo to Your WordPress Site
18How to Fix Error Establishing a Database Connection in WordPress

Cloudways: 30% OFF Deal

Save 30% on one of the best cloud hosting providers.

Get this Deal

Flywheel(our review)

Featured In Forbes Huffpost Entrepreneur SEJ

About WPKube

WPKube is an online WordPress resource which focuses on WordPress tutorials, How-to’s, guides, plugins, news, and more. We aim to provide the most comprehensive beginner’s guides to anything about WordPress — from installing plugins, themes, automated installs and setups, to creating and setting up pages for your website.

We have over 500+ tutorials, guides, product reviews, tips, and tricks about WordPress. Founded by Devesh Sharma, the main goal of this site is to provide useful information on anything and everything WordPress.

Twitter Facebook

Useful Links

  • Behind the Scenes
  • Beginner Guides
  • WordPress Hosting
  • WooCommerce Themes
  • MeridianThemes
  • Exclusive WordPress Deals
View All Guides »

Reviews

  • WPEngine 33% OFF
  • Thrive Leads
  • Flywheel 33% OFF
  • Divi Theme 20% OFF
  • Thrive Architect
  • Elegant Themes
Reviews »

Deals

  • InMotion Hosting
  • LifterLMS Coupon
  • LiquidWeb Coupon
  • WPEngine Coupon
  • A2 Hosting
  • FloThemes
More Deals »
© Copyright 2023 WPKube ® All Rights Reserved.
  • Contact
  • Site Terms
  • Disclosure
  • Privacy Policy