{"id":1410,"date":"2019-02-05T09:50:33","date_gmt":"2019-02-05T09:50:33","guid":{"rendered":"http:\/\/www.wordprax.com\/blog\/?p=1410"},"modified":"2019-02-12T13:01:55","modified_gmt":"2019-02-12T13:01:55","slug":"steps-to-fix-error-establishing-a-database-connection-in-wordpress","status":"publish","type":"post","link":"https:\/\/www.wordprax.com\/blog\/steps-to-fix-error-establishing-a-database-connection-in-wordpress\/","title":{"rendered":"Steps to Fix Error Establishing a Database Connection in WordPress"},"content":{"rendered":"<p><a href=\"http:\/\/www.wordprax.com\/blog\/wp-content\/uploads\/2019\/02\/Database-connection-error.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1413 alignnone\" title=\"Right Ways to Fix Error Establishing a Database Connection in WordPress\" src=\"http:\/\/www.wordprax.com\/blog\/wp-content\/uploads\/2019\/02\/Database-connection-error.png\" alt=\"\" width=\"794\" height=\"398\" srcset=\"https:\/\/www.wordprax.com\/blog\/wp-content\/uploads\/2019\/02\/Database-connection-error.png 794w, https:\/\/www.wordprax.com\/blog\/wp-content\/uploads\/2019\/02\/Database-connection-error-300x150.png 300w, https:\/\/www.wordprax.com\/blog\/wp-content\/uploads\/2019\/02\/Database-connection-error-500x250.png 500w\" sizes=\"auto, (max-width: 794px) 100vw, 794px\" \/><\/a><br \/>\nIf you are a WordPress website owner or a developer, you must have sometimes faced \u201cError establishing a database connection\u201d Error. It\u2019s obvious that you will be concerned but you should not worry too much as there is a solution to that. This problem can be fixed easily as this is a common WordPress error. First let\u2019s understand this problem i.e. what this error is all about? This error is self-explanatory i.e. it\u2019s an error in establishing a database connection. Actually WordPress uses PHP programming language and MySQL database. WordPress uses PHP commands to connect to the MySQL database, gets the information which is needed and then displays it on the screen. The error can come at this time.<br \/>\n<a href=\"http:\/\/www.wordprax.com\/blog\/wp-content\/uploads\/2019\/02\/Wordpress-Theme-Development.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"Wordpress Theme Development\" src=\"http:\/\/www.wordprax.com\/blog\/wp-content\/uploads\/2019\/02\/Wordpress-Theme-Development.png\" alt=\"\" width=\"600\" height=\"400\" \/><\/a><br \/>\nThis error occurs when, due to some reasons like issues with updation of <a title=\"Wordpress Theme Development\" href=\"https:\/\/www.wordprax.com\/services\/custom-wordpress-development\" target=\"_blank\"><strong>WordPress Theme<\/strong><\/a> or WordPress plugin, WordPress cannot access the information in the database via PHP commands. When this happens, WordPress gives the error \u201cError establishing a database connection.\u201d<\/p>\n<h4>Some of the most common reasons why this error occurs are: &#8211;<\/h4>\n<h4>Wrong Login Credentials<\/h4>\n<p>WordPress needs the correct login and password to access the database. If they have been changed then WordPress will not be able to fetch anything from the database.<\/p>\n<p>Corrupted WordPress files<\/p>\n<p>Sometimes due to failed update or due to other reason, the core WordPress files get corrupted. This can happen due to failed update of themes, plugins or the main WordPress software.<\/p>\n<h4>Corrupted Database<\/h4>\n<p>This can happen when an unstable or unsafe plugin messes with the database, due to a hacker\u2019s attack or when a theme fails.<\/p>\n<h4>The Database server is Down<\/h4>\n<p>Sometimes, the web server and the database server are installed on different systems and sometimes the database server may be down for some reason.<\/p>\n<h4>High Traffic<\/h4>\n<p>Sometimes due to high traffic, your database might become unresponsive.<\/p>\n<h4>Right Ways to Fix \u201cerror establishing a database connection\u201d: &#8211;<\/h4>\n<p>Now you know what this error is all about. So now let\u2019s discuss the right ways to fix this problem.<\/p>\n<h4>Contact Your Website Hosting Provider<\/h4>\n<p>If your website was working just few minutes ago and now it is not working, then there is a good chance that the problem might be at your website hosting\u2019s end. Hence contact your hosting provider through live chat or phone call and inform them about the error. In most cases, they will tell you the cause of the error and will fix it for you. They will tell you if your database is alright and whether there is a spike in traffic or whether there is some hacking attack on the server. If the problem is not on their end, then proceed to the next step.<\/p>\n<h4>Check if Your Theme Files or Plugin Have Been Corrupted<\/h4>\n<p>There are some instances when your WordPress files get corrupted. This may happen either when you have updated a theme or a plugin which resulted in the problem. If you have not updated anything then skip this step. Otherwise, first connect to your host via FTP using a tool like FileZilla. Login with the username and password you know. After that connect to the server and navigate to the WordPress root folder. It\u2019s generally called public_html or www.\u00a0 If you are there, then you should see the sub-folders like wp-content and wp-admin. Now go into the wp-content and rename the \u201cplugins\u201d folder. Go back to your site and see if the error is still there. If not, then now you know the error was due to some plugin. Now to find out the exact plugin which is causing the problem, go back to FTP, rename the folder back to \u201cplugins\u201d and change the folder names of the individual plugins, one by one and keep checking your website when the error comes and when it goes away. Once you find out the specific plugin which is causing the error, delete it or search on internet for the solution. If the error is still there even after checking all of the plugins, do the same process with the \u201cthemes\u201d folder. If this too doesn\u2019t work, then the error is caused by something else.<\/p>\n<h4>Check if Your Database Has Been Corrupted<\/h4>\n<p>The WordPress database is a complex thing and sometimes something wrong happens inside it and it throws the error \u201cerror establishing a database connection.\u201d First of all, check your WordPress dashboard \u2013 yoursite.com\/wp-admin<\/p>\n<p>If you still see the same error, then skip this step else see whether WordPress is suggesting something for you to do. WordPress has the ability to auto-resolve some of the problems and errors. If you see the message \u201cCan\u2019t Select the database\u201d then follow the steps WordPress is suggesting and your problem may get resolved. If you see a message \u201cOne or more database tables are unavailable..\u201d. Then you can repair the database by clicking on the Repair button which WordPress is showing. Once the automatic repair finishes, go back to your site and see if the error is still there. If error vanishes then you have done. Otherwise move on to the next step.<\/p>\n<h4>Check Your Database Connection Credentials<\/h4>\n<p>We have told you that WordPress uses the correct username and password to connect to the database. Generally, these access credentials remain same and you just have to remember them and use them as it is in the file wp-config.php.<\/p>\n<p>But sometimes due to some of your actions like when you make changes to your site files, the hosting environment or anything else, these access credentials might change and it starts throwing \u201cerror establishing a database connection\u201d error.<\/p>\n<p>As the username and password to connect to the database are stored in the file wp-config.php hence you can copy these details from this file and send to your hosting provider and ask them whether these details are correct or not. The company technical support professional will check these details and will come back to you with some feedback. They will provide you with the correct details if something has changed. You just need to login via FTP, download the file wp-config.php, do the required changes into the file and upload it back via FTP. Now check your site to see whether the error has been resolved or not. If not, then move on to the next last step.<\/p>\n<h4>Restore the Default WordPress Files<\/h4>\n<p>In some cases, the core WordPress files can get corrupted due to many reasons for example if there is a hacking attempt on your website or when you have modified some files by chance, or due to the installation of a bad plugin. Whatever reason it might be, you can still restore the default, native WordPress files. The best way to do that is to just download a clean version of WordPress from <a href=\"https:\/\/wordpress.org\/\" target=\"_blank\">WordPress.org<\/a> and copy it over the one you have right now. For this go to the WordPress official website https:\/\/wordpress.org\/download\/ and download the latest package to your desktop. Now connect to your website via FTP, go to the main WordPress root, upload your new WordPress files and overwrite all the previous files. After this step, check your website again and see the result. This will resolve almost all of your problems.<\/p>\n<h4>Conclusion<\/h4>\n<p>If you have followed all of the above steps and process carefully then you will surely resolve and fix the error \u201cerror establishing a database connection\u201d which you might have been facing with your <a title=\"Wordpress Web Development\" href=\"https:\/\/www.wordprax.com\" target=\"_blank\"><strong>WordPress website<\/strong><\/a>. If in some rare case, the error still comes then you have no choice than contacting your website hosting provider and telling them everything what you have done, what worked and what didn\u2019t. Now it is the hosting provider who can do something to resolve this issue. If you wanted to avoid this error from coming in future, then you should take some steps. First thing is that always go for quality hosting. Choose the one which has optimized their platforms to work with WordPress. Second most important thing to do is to have backups. Install a simple backup plugin which works automatically and you will always have a working WordPress backup which you can restore anytime when everything else fails. I am sure the above steps will help you in resolving and preventing the error \u201cerror establishing a database connection\u201d with your WordPress website.<\/p>\n","protected":false},"excerpt":{"rendered":"If you are a WordPress website owner or a developer, you must have sometimes faced \u201cError establishing a database connection\u201d Error. It\u2019s obvious that you will be concerned but you should not worry too much as there is a solution","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[42],"tags":[197,185,93],"class_list":["post-1410","post","type-post","status-publish","format-standard","hentry","category-wordpress-theme-customization","tag-wordprax-reviews","tag-wordprax-reviews-ltd","tag-wordpress-theme-development-2"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.wordprax.com\/blog\/wp-json\/wp\/v2\/posts\/1410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wordprax.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wordprax.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wordprax.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wordprax.com\/blog\/wp-json\/wp\/v2\/comments?post=1410"}],"version-history":[{"count":10,"href":"https:\/\/www.wordprax.com\/blog\/wp-json\/wp\/v2\/posts\/1410\/revisions"}],"predecessor-version":[{"id":1419,"href":"https:\/\/www.wordprax.com\/blog\/wp-json\/wp\/v2\/posts\/1410\/revisions\/1419"}],"wp:attachment":[{"href":"https:\/\/www.wordprax.com\/blog\/wp-json\/wp\/v2\/media?parent=1410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wordprax.com\/blog\/wp-json\/wp\/v2\/categories?post=1410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wordprax.com\/blog\/wp-json\/wp\/v2\/tags?post=1410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}