How to fix Error Establishing a Database Connection (WordPress)

Getting an error like Error Establishing a Database Connection in WordPress? Check this post on how to fix this error.

\r\n\r\n\r\nIf you are a regular internet user and you do browse some blogs or websites which require connection to database, like WordPress, Forums or other CMS, then you would have surely experienced an error like “Error establishing a database connection” . If you are just a visitor, then you can not do much about this error, but if you are the webmaster and getting this error on your own website, then it might be a big issue specially when you are not a coder and you do not know much about WordPress and PHP coding.\r\n\r\nHaving a WordPress blog on shared hosting might make you experience this error again and again. This error might occur anytime at any phase. Being honest, there is nothing you can do before this error occurs, because this is not a security issue that it comes and goes once you install a security plugin or change your password, nor there is a way which you can implement and be sure that you wont get to see Error establishing a database connection error again.\r\n\r\nIn this post, I will be discussing on how you can overcome Error establishing a database connection error. But before that, let me discuss\r\n

Why does Error establishing a database connection error occur?

\r\nAs the error name tells, this error occur when your CMS (WordPress or anything else you are using) remains unable to communicate with your database server for the proper exchange of data and your website goes down, in that condition, you see an error on your screen which says Error establishing database connection. About all the situation where this error might occur and their solutions, I will be discussing later in this post.\r\n\r\nFirst of all,\r\n\r\nMake sure what all places are affected\r\n\r\nThere are mainly 2 areas of your blog and website. First one is the part which is visible to all the visitors, that is called front end, the other part is visible to only the administrators and some other privileged members which is called back end, where you do all the changes which reflect on your main website.\r\n\r\nFor example, if you are having a WordPress blog, then the home page where your posts are visible is called front end and that dashboard which you use to install plugins and write new posts is said to be back end.\r\n\r\nIf you are getting the error on both the places or the error at both the places is different, then you will need to repair your database. That can be done using the WordPress dashboard, but this error won’t leave your dashboard accessible, so you will need to open your ftp client, locate for the wp-config file and add the below written statement on that file.\r\n

define('WP_ALLOW_REPAIR', true);

\r\nNow upload your wp-config file once again back to the server and now go to http://www.yoursite.com/wp-admin/maint/repair.php (yoursite.com should be replaced with the your blog URL)\r\n\r\nYou will get a screen like the one shown below in the screenshot\r\n\r\nwordpress database repair\r\n\r\n \r\n\r\nClick on Repair database and it will take some time to repair your database for all possible error. You will not need to be logged in because the only purpose of yours for now is to repair a corrupt database. Once the repair is done, when the main homepage of your blog, if it is working fine, you are done, or if it is still showing the same problem, then you can move further. In both the cases, you will need to delete the one line statement which you had just added to the wp-config file.\r\n

How to fix error establishing a database connection in WordPress

\r\nCheck Wp-config.php file\r\n\r\nWp-config.php is the file which connects your WordPress script and the database. If you have ever installed WordPress manually, then you would be knowing you need to enter your credentials in the same file when you are installing WordPress. So there are high chances that because of an error in the information on this file, you might get this error.\r\n\r\nTo make sure all the details you provided on this file are correct, just log into the cpanel of your hosting, and check the user name, database name and the database password and match it with the credentials present in the wp-config file. If the credentials do not match, then you can simply change them in the wp-config file and upload the file back on the server.\r\n\r\nIf you find the credentials same on the database as well as on the wp-config file, then you can just try to change the user name and password of database and try again to load the website.\r\n\r\nThis error would work in 99% of the situations, if you still get this error, then try to contact your hosting provider and get the issue solved.\r\n\r\nI hope this post was useful. Let me know if you have doubt in anything related to blogging. I will try my level best to solve them for you.\r\n\r\n

Leave a Comment

Your email address will not be published.