Press "Enter" to skip to content

Error Establishing Database Connection in WordPress

WordPress powers about 30% of the internet today. It is so easy to create a website or a blog using WordPress. You just have to worry about creating content and WordPress will take care of everything else. But sometimes when you type-in the url of your website or your blog you will see the Error Establishing Database Connection  in WordPress. Its one of the errors that pops up quite commonly when you are using WordPress (Some of the other error you encounter using WordPress). Most of the WordPress user panic when they see this error. And there is a good reason for doing so because there is no good article available over the internet to solve this problem. But now the things are going to change. In this article I am going to show you how to solve the error establishing database connection in WordPress.

Why do you get the error establishing database connection in WordPress?

Well simply put if you are getting the error establishing database connection in WordPress it simply because WordPress is unable to establish database connection. As you know that WordPress is developed in PHP and MySQL. PHP handles all your website functionality and MySQL deals with data – storage. PHP needs MySql to pull the data so that your website can show it to the user. If by any chance PHP is unable to contact the database the error establishing database connection is shown. There are many reasons for this error. It could be that your database server become unresponsive. Maybe your database is corrupted or maybe your database credentials have been changed and many more. Let’s take a look at some of the basic reasons of getting this error and how we can solve the problem.

Check whether your database has been corrupted?

To check whether or not your database has been corrupted you need to make sure that you are getting the same error on both the front end and the back end(wp-admin) of your website. If you are getting the same error i.e error establishing the database connection, on both ends of the website then your database is not corrupted and you can safely switch to the next step.

But if you are getting different error(different from infamous error establishing database connection) on the back end(wp-admin) of your website like “One or more database tables are unavailable” then your database is corrupted and you have to repair your database. You can repair your database by adding the following line in your wp-config.php file. Add it just before ‘That’s all, stop editing! Happy blogging’ line wp-config.php.

define('WP_ALLOW_REPAIR', true);

Once you done that visit the following page Obviously you have to write the name of your website in place of “yoursite”. You can see the image belowerror establishing database connection

Press the repair database button and it will repair the database for you. Remember the user does not need to be logged in to access this functionality. So once you are done repairing and optimizing your database make sure to remove the line from the wp-config.php file.

Check your database credentials

All your WordPress database configuration resides in a file called wp-config.php. It is one of the most important file in your WordPress installation. It contain the details for WordPress to connect with your database. If you have changed your database login credentials or you database credentials have been changed then you will need to change this file as well. First thing you should always check is if everything in your wp-config.php file is the same.

define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');

Here database name is the name of the database which is being accessed by WordPress. And database-username will be username and database-password will be the password required to access the database. Remember your DB_Host value might not always be localhost. Depending on the host, it will be different. For popular host like bluehost, hostgator it will be localhost.

If everything in this file is correct then you can be sure that something is wrong in the server end.

Check your Web Host

You will get error establishing database connection when your website is getting a lot of traffic. Basically your web host is unable to handle the traffic. Your site will get really slow and some of your user will see error establishing database connection message on their screen. So the best thing that you can do in this situation is get on the phone or livechat with your hosting provider and ask them if your MySQL server is responsive.

You can also check manually whether your MySQL server is running or not by following the steps given below:

  1. Test other sites on the same server and see whether they have the same issue or not. If they are getting the same error then there is something definitely wrong with the MySQL server.
  2. You can also go to your c-panel account and try to access phpMyAdmin and connect the database. If you cannot connect to database by going to phpMyAdmin then you know there is something definitely wrong with your server

That’s all for today. Stay tune for the next tutorial. If you have not subscribe to our weekly newsletter then please do it by clicking the link below

subscribe Button HERE

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    If you like our content then please subscribe