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.
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 your website again.
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:
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.
Open that file and verify that your database information are correct, it looks like the below screenshot:
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 new database 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:
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 set 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. They are low-quality services, and they will destroy your website easily. 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 a daily database error 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. I recommend Inmotion Hosting, as the best shared hosting. It’s an optimized for WordPress.
If you want the top quality, and premium managed web hosting, 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 work again, even if the database works properly.