{"id":694,"date":"2017-05-03T19:44:50","date_gmt":"2017-05-03T19:44:50","guid":{"rendered":"https:\/\/chemicloud.com\/kb\/?post_type=article&#038;p=694"},"modified":"2024-10-16T09:45:05","modified_gmt":"2024-10-16T09:45:05","slug":"troubleshooting-wordpress-error-establishing-database-connection","status":"publish","type":"ht_kb","link":"https:\/\/chemicloud.com\/kb\/article\/troubleshooting-wordpress-error-establishing-database-connection\/","title":{"rendered":"Troubleshooting the WordPress &#8220;Error Establishing Database Connection&#8221;"},"content":{"rendered":"<p>If you&#8217;ve recently attempted to reach your WordPress-based website and instead received a message stating &#8220;<strong>Error Establishing Database Connection<\/strong>&#8220;, the cause is most often one of the following:<\/p>\n<ul>\n<li>The database has crashed<\/li>\n<li>The database login credentials are incorrect in your WordPress configuration file<\/li>\n<li>The WordPress database tables have been damaged<\/li>\n<\/ul>\n<p>We will walk through these issues one at a time to determine if they affect you, and how to fix them.<\/p>\n<div data-unique=\"step-3-\u2014-repairing-the-wordpress-database\">\n<h3 id=\"step-3-\u2014-repairing-the-wordpress-database\"><span id=\"step-1-try-repairing-the-wordpress-database\">Step 1 \u2014 Try repairing the WordPress Database<\/span><\/h3>\n<p>Sometimes, due to a failed upgrade, a database crash, or a faulty plugin, your WordPress database can become corrupted. This problem can present itself as a database connection error. The first thing you can do is try repairing your database.<\/p>\n<\/div>\n<div data-unique=\"step-3-\u2014-repairing-the-wordpress-database\">If you are using cPanel as a control panel at the actual web host, you can easily <a href=\"https:\/\/chemicloud.com\/kb\/article\/how-to-check-or-repair-mysql-database\/\" target=\"_blank\" rel=\"noopener noreferrer\">repair your WordPress database<\/a> through <strong>phpMyadmin<\/strong>.<\/div>\n<div data-unique=\"step-3-\u2014-repairing-the-wordpress-database\"><\/div>\n<div data-unique=\"step-3-\u2014-repairing-the-wordpress-database\">\n<p>Additionally, WordPress provides a built-in functions to repair the database. It is disabled by default because it has no access controls and could be a security issue. Below, you will see how we will enable the feature, run the repairs, and then disable it to avoid this potential security threat.<\/p>\n<p>Open the wp-config.php file. On any blank line, paste in the following:<\/p>\n<pre class=\"code-pre \"><code>define('WP_ALLOW_REPAIR', true);<\/code><\/pre>\n<\/div>\n<div data-unique=\"step-3-\u2014-repairing-the-wordpress-database\">\n<p>This defines a variable that WordPress looks for when determining if it should enable the repair feature.<\/p>\n<p>Save and close the file. Switch over to your browser and load the following address, being sure to substitute with your site&#8217;s domain.<\/p>\n<pre>http:\/\/www.yourdomain.com\/wp-admin\/maint\/repair.php<\/pre>\n<p>A database repair page will load.\u00a0Press the <strong>Repair Database<\/strong> button, and you&#8217;ll be taken to a results page where you can see the checks and repairs happening in real-time.<\/p>\n<p>Once the process finishes, be sure to open up the wp-config.php file again and remove the line we just pasted in.<\/p>\n<p>Did you notice any repairs being made? Try your site again, and check whether the error is gone.<\/p>\n<h3 id=\"step-2-check-database-login-credentials\">Step 2 \u2014 Check Database Login Credentials<\/h3>\n<p>If you&#8217;ve just moved your WordPress site between servers or hosting providers, you might need to update your database connection details. These are stored on the server in a PHP file called wp-config.php.<\/p>\n<p>Now use your favorite text editor to open the configuration file. Locate the database connection information:<\/p>\n<pre class=\"code-pre \"><code>\/** The name of the database for WordPress *\/\r\ndefine('DB_NAME', '<span class=\"highlight\">database_name<\/span>');\r\n\r\n\/** MySQL database username *\/\r\ndefine('DB_USER', '<span class=\"highlight\">database_username<\/span>');\r\n\r\n\/** MySQL database password *\/\r\ndefine('DB_PASSWORD', '<span class=\"highlight\">database_password<\/span>');<\/code><\/pre>\n<p>Check that these three variables are correct based on your records. If they don&#8217;t look right, update as appropriate, save and exit.<\/p>\n<p>If the steps above didn&#8217;t solve your issue, you might need to restore the database from a backup if you have one available.<\/p>\n<p>If you&#8217;re a ChemiCloud customer, you can rest easy! All our <strong>WordPress hosting<\/strong> plans come with 30 day daily offsite backups allowing to be quickly restored.<\/p>\n    \t\t<div class=\"hts-messages hts-messages--info    \"   >\r\n    \t\t\t    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tIf you enjoyed this tutorial, then you\u2019ll love our support! All ChemiCloud\u2019s hosting plans include 24\/7 support from our amazing support team.<\/p>\n<p class=\"p1\">Check out our <a href=\"https:\/\/chemicloud.com\/managed-wordpress-hosting?utm_source=blog&amp;utm_medium=article#60b65e4e63b58\"><span class=\"s1\">Managed WordPress hosting<\/span><\/a>\u00a0plans and have your website migrated today!<\/p>\n    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve recently attempted to reach your WordPress-based website and instead received a message stating &#8220;Error Establishing Database Connection&#8220;, the cause is most often one of the following: The database has crashed The database login credentials are incorrect in your WordPress configuration file The WordPress database tables have been damaged&#8230;<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"ht-kb-category":[40],"ht-kb-tag":[],"class_list":["post-694","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-wordpress"],"_links":{"self":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/comments?post=694"}],"version-history":[{"count":10,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/694\/revisions"}],"predecessor-version":[{"id":8510,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/694\/revisions\/8510"}],"wp:attachment":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/media?parent=694"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=694"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}