Error Establishing a Database Connection in WordPress: Fix it now

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 on 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 other than wait sometime 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 log in 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.

Related:  How to find a specific line of code in WordPress

2. Incorrect Database information

Sometimes, your database username and password can be copied in the wrong way. A small space can stop your blog from 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 are 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 browse 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 of 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 from working until the total connected databases will be acceptable.

Related:  How to Fix the WordPress Visual Editor Problem Easily

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 with 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 additional traffic. The solution is simply to change your actual host without waiting.

If you want the top quality, and premium managed to host, then use WP Engine 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.

Avatar for Fathi Arfaoui
About Fathi Arfaoui

Fathi Arfaoui is a Physicist, Blogger and the founder of Trustiko.com. He shares Business, WordPress and Blogging tips to build a better blog and succeed online.

Disclosure: The recommendations on this page are my own based on my tests and analysis. We may earn a small commission from web hosts and other partners if you use my referral link to make a purchase. That’s what helps us to maintain the site and add fresh content, Thanks for your support.

Leave a Comment