• 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
  • Themes
    • Elegant Themes
    • Thrive Themes
    • OptimizePress
  • Hosting Reviews
    • WPEngine
    • Flywheel
    • A2 Hosting
    • SiteGround
    • Kinsta
  • Coupons
    • WPEngine
    • Flywheel
    • HostGator
    • A2 Hosting
WordPress Tutorials

How to Fix Error Establishing a Database Connection in WordPress

Last Updated on: September 12, 2020 Freddy Muriuki 70 Comments

How to Fix Error Establishing a Database Connection in WordPress

When you start using WordPress, you’re bound to encounter a number of errors, some grievous, other not so much. It’s inevitable; it can be your fault, at times systems break, someone fails at their job, natural calamities strike – anything could cause an error.

Even something as good as an increase in traffic can break your WordPress site, leaving you with an error and a bad taste in your mouth.

Now, just like any other human-made project, WordPress is susceptible to its share of errors, none of which is as baffling and strenuous as the “error establishing database connection” error. That’s because this error doesn’t come with details of what went wrong, despite that it can be caused by several things, which – of course – only adds salt to the wound.

All you get when you try loading your site is:

error establishing connection

In today’s post, we will look a little deeper into this WordPress error, and then cover some of the solutions you can use to restore your site to its former glory. Enjoy and please share your tips and solutions, or ask your questions in the comment section at the end.

What Does “Error Establishing a Database Connection” mean?

To give you an insider’s understanding of the “EEDC” error, we first need to break down WordPress into its two fundamental components.

WordPress is built using PHP (e.g. index.php, sidebar.php etc) and MySQL. PHP is in charge of all functions on your WordPress site (e.g. posting comments, retriving posts and pages etc) and MySQL is in charge of data storage.

For instance, when you type your URL in the address bar and hit enter, PHP kicks in, fetches and displays the contents of the homepage (index.php) from your MySQL database. Images, videos and such media are, however, stored in the wp-content folder, from where they’re retrieved by PHP.

Your MySQL database contains all the vital information PHP needs to create your site. Now, when PHP can’t access your MySQL database for one reason or another, you get the dismaying “error establishing database connection” message on your screen. Which is just PHP-speak for I couldn’t find the data I needed to put together you WordPress site. Here’s an error to show you I tried.

That said, the “EEDC” error can be caused by a number of reasons including but not limited to:

  • Incorrect login details; typos, wrong quotes and extraneous spaces – Changes to your database login details can “block” your website from accessing the database.
  • Unresponsive database server – The server where your database lives could be as dead as a dodo; caput, unresponsive or still recovering from a traffic upsurge.
  • Corrupted WordPress files
  • A corrupted database – Bad plugins, addons, themes and data-transfer interruptions might leave your database short of tables or completely corrupted at worst.

In the next section, we’ll outline the most common solutions that are known to work.

Troubleshooting “Error Establishing Database Connection.”

Of course, we would be insane if we tried to fix the problem without first establishing the cause. If we can determine the root of our error, then getting a viable solution is a matter of when.

Is Your WordPress Database Corrupted?

We can start by checking whether the error is as a result of a corrupted database. For this, we have to test if the error has crippled the back-end as well.

All you have to do is navigate to yoursite.com/wp-admin/. Please don’t forget to replace yoursite.com with your own domain name.

If loading the front-end (i.e. yoursite.com) and the back-end (i.e.  yoursite.com/wp-admin/) results in the “EEDC” error, your database is fit as a fiddle, and you needn’t concern yourself with the next step. You can skip all the way to determining whether you have the correct login credentials in your wp-config.php file.

However, if you’re getting “One or more database tables are unavailable…” or something else but the infamous “EEDC” error, your database is corrupted and in die need of repairs.

Don’t worry one bit though, as repairing your WordPress database is easy peasy work. You can be done in three simple steps. Firstly, locate the wp-config.php file, which lives in your WordPress root directory. The root directory is the folder where your WordPress site is installed.

You can usually find this folder inside the default home folder or “public_html”. Just login to your cPanel, and navigate to File Manager.

cpanel-file-manager-in-bluehost

Then navigate to your WordPress root folder:

open-file-manager

Locate your WordPress Root Folder Here

From this point, locating your wp-config.php file should be easy:

locating-wp-config-file-in-wordpress-root-folder

Once you have access to wp-config.php, open it in editing mode. Right click on the file to choose the code editor, or select code editor in the menu:

editing-wp-config-using-the-code-editor-menu-item

This will open your wp-config.php in a new tab. Add the following code at the bottom:


define ( 'WP_ALLOW_REPAIR' , true);

Save your changes.

The above code allows you to repair your WordPress database without having to login into phpMyAdmin manually, which might be quite a tussle depending on your experience.

The second step involves navigating to yoursite.com/wp-admin/maint/repair.php. This should open the following screen:

wordpress-database-repair-screen

Third step, just choose either “Repair Database” or “Repair and Optimize Database” and let WordPress do the rest.

NB: Once your database is repaired, remember to delete the code you added to your wp-config.php file. Otherwise, you risk granting hackers access to your database, where they will wreck havoc.

If repairing your database solved the error, well and good, just go ahead and pop the bubbly. If you’re still seeing the error after repairing the database, perhaps the error stems from incorrect login details, corrupted WordPress files or an unresponsive database server.

Let’s check whether your database login details are the problem.

Checking Your Database Login Credentials

Open your wp-config.php once again 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 where you put your password e.g. ‘test!@#!@#’
  • ‘localhost’ – This is where you input your database host. The default is ‘localhost’ for most web hosts.

If any of these four credentials are incorrect, you will get the “error establishing database connection” error.

At this juncture, all you have to do is counter-check these credentials against those stored in your database. It’s easy peasy work.

First, let’s check if you have the correct database name in your wp-config.php. Follow the following steps:

From your cPanel, go to phpMyAdmin. In most hosting accounts such as Hostgator, Goaddy, and BlueHost, phpMyAdmin is usually located under the database tools tab:

database

The first screen you will see after clicking phpMyAdmin is the login screen:

phpmyadm

Once you’re logged into phpMyAdmin, click on the Databases tab to query a list of your databases:

databases-tab-in-phpMyAdmin

From the list of databases, can you see the database that appears after DB_NAME in your wp-config.php file?

list-of-databases-in-phpmyadmin

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 backup 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.

Checking 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.

This you can do easily by opening your WordPress root folder and clicking New File on the menu:

create-a-new-php-file-in-wordpress-root-folder

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, username and password in wp-config.php respectively. Save changes, and navigate to yoursite.com/check.php. If you get “Connected successfully”, your login details are correct.

If you get “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. To get the new credentials, you need to create a new user, which is also as easy as A, B, C.

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.

Creating 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:

phpmysql

Clicking on MySQL Databases should open something like this:

mysql-databases-screen

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

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:

add-new-user-to-database

Select the user you just created and your database, and click Add. You can choose the user privileges in the next screen, but that’s not really important. Choose “All Privileges” if you must, and save changes.

Go back to wp-config.php and update the file with the new information. Make sure there are no spaces between the quotes. For examples, ‘ 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.

Are you still getting the error? If that’s a yes, the problem could be corrupted WordPress files.

Fixing Corrupted WordPress Files

Bram Valk once had the error after including interrupting PHP files in his footer. It could have caused him a lot of trouble had he not known the files were the problem, so he just eliminated the problematic files, and the error was gone.

Your error could be as a result of corrupted WordPress files, which shouldn’t worry you as other users have resolved this error simply by restoring their WordPress files. You need to be careful here because a tiny mistake can wipe away your entire site. First, make sure you back up your entire WordPress site before proceeding.

Then download a fresh copy of WordPress from WordPress.org. Unzip the package on your computer and then delete wp-config.php as well as the wp-contents folder. This will ensure you don’t break your existing wp-config.php file. It will also ensure you don’t lose the themes, plugins and media stored in wp-content once you restore WordPress.

Once you have this covered, upload the remaining files to your WordPress root folder using FTP or the File Manager. This should replace all problematic files.

Try reloading your site, and if you’re still seeing the error, first try cleaning your browser’s cache. If the error persists after  cleaning your cache, please ask your question in the comments, and we will come to your aid.

Additionally, please feel free to contact your web host because the problem could be on their side.

Final Thoughts

At the end of the day, you should not sweat when you encounter this error. As we’ve outline here today, it’s really simple to resolve, and should you run into any problem, your web host is always at your beck and call.

We are also always here to help you. We might not fix the error (if the problem is with your host) but we can and will always hold your hand and help you the best way we can.

We hope this article helped you learn how to fix the “Error Establishing a Database Connection” error in 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

Freddy Muriuki

Freddy is a WordPress theme reviewer at WP Theme Raves, published WordPress blogger, web dev and founder of Vista Media Enterprises, an online business dedicated to WordPress users looking to boost conversion rates via content marketing.

Related Posts

Back to all articles
  • Implementing a GraphQL server with components in PHP

    Implementing a GraphQL server with components in PHP

  • How to Start a WordPress Blog (Step by Step Guide)

  • How to add HTTPS and SSL to WordPress – Step by Step Guide!

Coupons

View more deals
  • Nexcess coupon code
    Save 40%

    Nexcess Coupon

    Looking to save money on managed hosting from Nexcess?
    Get This Deal
  • 33% OFF

    Flywheel Hosting Coupon

    Hosting isn’t always the most simple portion of your websit
    Get This Deal
  • TailorBrands
    25% Off

    Tailor Brands Coupon

    Looking for a Tailor Brands coupon to save on your own custom log
    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.

loader

THE BEST OF WPKUBE

Some of the best content we have published so far.

BEGINNER GUIDES & REVIEWS

1How to Start a WordPress Blog (Step by Step Guide)
2How to Install WordPress - The Complete Guide
36 Best Options for Managed WordPress Hosting Compared
4The 7 Best WordPress Hosting Providers for 2021 Compared
5Top 9 Landing Page Plugins for WordPress (2020)
69 Best List Building Plugins for WordPress In 2021
7How to Fix the 500 Internal Server Error on Your WordPress Website
8Beaver Builder Review: Is it The Best Page Builder Plugin for WordPress (2021)?
9What is a Gravatar and Why You Should Get One
10Thrive Themes Review: A Look At The Full Membership
117 Best WordPress Migration Plugins Reviewed and Compared for 2021
12OptimizePress Review: Create Landing Pages with Ease
13How to Make a Website: Complete Beginner's Guide
14WordPress.com vs WordPress.org: Which is Best for Me?
15Top 22 Best Free Stock Photo Resources For Your Site
1617 of the Best Google Fonts (And How to Use Them in WordPress)
17LifterLMS Review: Is it The Ultimate WordPress LMS Plugin?
18How To Fix '503 Service Unavailable' WordPress Error
1911 Best Contact Form Plugins for WordPress in 2021
20How to Use BackupBuddy – The Best Backup Solution for WP??
21How to Add a Custom Logo to Your WordPress Site
22Kinsta Review: Real Test Data + My Likes And Dislikes
23How to Fix Error Establishing a Database Connection in WordPress
24Thrive Architect Review 2020 – Best Landing Page Plugin for WordPress!

Exclusive deals

Flywheel Elegant Themes Coupon WPEngine Coupon A2 Hosting

WPEngine: 50% OFF Deal

Save 50% on one of the best managed 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.

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
More Deals »
© Copyright 2020 WPKube ® All Rights Reserved.
  • About
  • Contact
  • Site Terms
  • Disclosure
  • Privacy Policy