Error Establishing a Database Connection in WordPress: Fix it now

In WordPress by Fathi Arfaoui4 CommentsLast Updated: September 15th, 2017

Blogging in WordPress is a pleasure, but sometimes. It can be turned into a big problem, especially, when you get the “Error establishing a database connection” message, while you trying to access your WordPress admin page. Or, any other normal page in your blog, this error will stop everything in your website and the big problem is that you can’t even access the dashboard.

Things will be complicated, even more, when you can’t find why you get an error establishing a database connection without any helpful information.

Error Establishing a Database Connection in WordPress

Today, I’ll show you why you see that database error in WordPress. There are many reasons, and you have to know them one by one, to fix the problem.

Causes for “error establishing a database connection” in WordPress

To make things clear, it can be your problem and in other cases, you don’t have to do anything than wait some time and your blog will work again. As the error message itself shows, there is a problem between the Database and the WordPress core. That means that WordPress and your MySQL database connection is broken for many reasons.

1. MySQL server is down temporary

This seems a rare situation, but it’s really one of the most common causes for the database connection problem. This happens many times for new web hosting companies, and you need to wait some minutes and check again your website.

I started with this verification process to make to avoid doing anything in your files and kill yourself for a solution. To verify this first probable cause, just login to your cPanel account and click the PHPMyAdmin icon as below:

phpMyAdmin login

Now, wait some seconds until the database tables appear. If you get an error about the database, and the service is currently unavailable. Then, the database is down for maintenance or any other reason, and you can’t do anything, then just waiting some minutes.

There is another solution, click your database name from the MySQL database names. Verify that the user privileges are checked. If all the options are unchecked, correct the problem and check them, and save the changes.

If your PHPMyAdmin database appears normally, then, you need to look at the next step.

2. Incorrect Database information

Sometimes, your database username and password can be copied by the wrong way. A small space can stop your blog working completely. So, the first thing you have to do is to verify your Database, username, database password, and username, in the ”wp-config.php” file, located in the WordPress directory.

Error Establishing a Database connection fix

Open that file and verify that your database information is correct, it looks like the below screenshot:

verify database name, username and password

Please make sure that every detail should be entered between the two ‘ and ‘ or your information will be wrong. If you can’t remember your database username or password, you can create a new database user, and replace the old database information above.

To create a database new user, locate the icon MySQL database into your cPanel account, and click on it. Then, scroll down until you find the form to create a new user as below:

add new database user

Don’t forget to check all the boxes on the next page, where you allocate permissions to the new user.

After adding your new user and password, save the ”wp-config.php” file, and refresh your browser page, change the browser to verify even more.

3. Corrupted database tables

The database tables can be corrupted and make the connection between WordPress, and the database impossible with that problem. You can check if your tables are really corrupted or not, by logging into cPanel, then click “phpMyAdmin” and “check all” tables, from the drop down menu, select “Check Table”.

If you get an error and not “OK” in all tables. Then you need to repair the database tables. All you have to do is check all tables again, and select “Repair Table” from the drop down menu.

 4. Too many databases

This is another common issue, even the biggest web hosting companies, will limit the number database connections at the same time. Some sets 20 and others 30. So, if you have many databases, verify that there is no automatic execution process that can cause the problem. That can be a plugin that works at the same time in all your databases. That can stop the entire blog working until the total connected databases will be acceptable.

If you have installed databases that you don’t use anymore, you should delete them to avoid any problem with your hosting settings.

5. Poor server configuration

The database connection error can also happen with free hosting, that are low quality, and even destroying services. The real hosting company needs resources to make your blog available all the time. If your blog is hosted on those low quality hosting servers, then, expect daily database errors without any solution.

It’s not a thing that can be repaired. But, the company itself is unable to make thousands of sites works properly when the is an additional traffic. The solution is simply to change your actual host without waiting. If you want the top quality, and premium managed hosting, then use the WP Engine managed hosting for WordPress and InMotion for all the applications, they’re great for their amazing services, and fastest customer support.

If you can’t get your blog to work again with all the above verification, then, you should contact your hosting provider, and ask them to verify the problem. Make sure to create a screenshot of the exact error message you have. It can contain helpful details to fix the database connection error.

At the same time, don’t try to change anything in your WordPress files. It can create another problem, and you risk your site to works again even if the database works properly.

About Fathi Arfaoui

Fathi Arfaoui: A Physicist, Blogger, and the founder and owner of Trustiko.com. He shares Business, Blogging, WordPress, Web Safety, and Blogging tips to build better websites and blogs. Also, he shares online marketing strategies and recommendations.

Comments

  1. I had this issue today.
    Server had crashed last night and was attended to fairly quickly when the issue was known.
    All worked for a while but today WordPress couldn’t make a connection to the database.
    The Simple Machines Forum database was working ok and the forum would load.
    What I did was:
    1. Create a new database user
    2. Assigned that user to the WP database with full privileges.
    3. Updated WP_config to use that user

    After that all was good.

    Seems that after a server issue the WordPress user privileges can become corrupt or changed even though the user is shown with full privileges.

    Thanks for this post. It pointed me in the right direction.

    1. Author

      Good to hear that you’ve fixed the problem, yes the WordPress database tables and the user permissions can easily be broken in different cases that no one can expect, such as brief electric failure, wrong php executions, and many others, you’ve made the right decision by reinstalling the database again with new user. Good Luck.

  2. Actually, I’m getting “Error establishing a database connection” in my home page only. All other pages are working fine. Please let me know what to do.

    1. Author

      Try to delete the cache first, then, try with another browser. If the website works with others pages, it can be an issue with the cached pages.

Leave a Comment