{"id":116982,"date":"2023-02-04T13:54:07","date_gmt":"2023-02-04T13:54:07","guid":{"rendered":"https:\/\/wpsimplefix.com\/?p=116982"},"modified":"2026-09-24T17:41:59","modified_gmt":"2026-09-24T17:41:59","slug":"error-establishing-a-database-connection-on-wordpress","status":"publish","type":"post","link":"https:\/\/chkserv.com\/blog\/error-establishing-a-database-connection-on-wordpress\/","title":{"rendered":"Error establishing a database connection on WordPress"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">All the essential data, including posts, pages, users, and plugin settings, is stored in the database. Without it, your website won&#8217;t function at all and will give you and your visitors an error if it can&#8217;t access the database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are numerous causes for this error to appear, including, for example, a broken update, a server crash, incorrect configuration file editing, or exceeding server limits. This file is crucial since it contains all of the details about your website.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To fix the database connection, log in to your FTP and open the wp-config file.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/chkserv.com\/blog\/wp-content\/uploads\/2023\/02\/ftp-wpconfig-1024x858.png\" alt=\"ftp-wpconfig\" style=\"aspect-ratio:1.1940298507462686;width:800px;height:auto\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check that the database details are correct, like database name, user and password. You can find this information by logging into your cPanel account or PhpMyAdmin or contact your host, if they don\u2019t use a control panel. If the hostname, username, password, or database name in the file are incorrect, replacing them should fix the error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If all the information is correct, lets continue.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress has a built in feature which can fix a corrupted database, and can be turned on by placing the following code in the wp-config.php file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-1\"><code readonly=\"true\">define( 'WP_ALLOW_REPAIR', true );<\/code>\t\t<\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Repair Database<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After saving the file and uploading it back to your server, you can run the new script by navigating to <i>https:\/\/your-website.com\/wp-admin\/maint\/repair.php<\/i>&nbsp;in your browser<i>. <\/i>The resulting page will look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/chkserv.com\/blog\/wp-content\/uploads\/2023\/02\/repair-databse.jpeg\" alt=\"repair-databse\" style=\"aspect-ratio:1.8691588785046729;width:800px;height:auto\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Click the &#8216;Repair Database&#8217; button and let it work its magic. On a typical site it will take less than 30 seconds, of course the bigger the database the longer it will take, be patient.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once complete, it will display a list of your database tables and hopefully have \u201cOkay\u201d next to them all. This should deal with your database connection error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Finishing Up<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Don\u2019t forget to remove the line <strong>below<\/strong>&nbsp;from <i>wp-config.php<\/i>&nbsp;when you\u2019re done<i>.<\/i><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\t\t\t\t<code readonly=\"true\">\n\t\t\t\t\t<xmp>define( 'WP_ALLOW_REPAIR', true );<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>All the essential data, including posts, pages, users, and plugin settings, is stored in the database. Without it, your website won&#8217;t function at all and will give you and your visitors an error if it can&#8217;t access the database. Why? There are numerous causes for this error to appear, including, for example, a broken update, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":121200,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[26,52,45,53,54,7,55],"class_list":["post-116982","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","tag-connection","tag-database","tag-error","tag-ftp-2","tag-phpmyadmin","tag-wordpress","tag-wp-config"],"_links":{"self":[{"href":"https:\/\/chkserv.com\/blog\/wp-json\/wp\/v2\/posts\/116982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chkserv.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chkserv.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chkserv.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chkserv.com\/blog\/wp-json\/wp\/v2\/comments?post=116982"}],"version-history":[{"count":1,"href":"https:\/\/chkserv.com\/blog\/wp-json\/wp\/v2\/posts\/116982\/revisions"}],"predecessor-version":[{"id":136705,"href":"https:\/\/chkserv.com\/blog\/wp-json\/wp\/v2\/posts\/116982\/revisions\/136705"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chkserv.com\/blog\/wp-json\/wp\/v2\/media\/121200"}],"wp:attachment":[{"href":"https:\/\/chkserv.com\/blog\/wp-json\/wp\/v2\/media?parent=116982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chkserv.com\/blog\/wp-json\/wp\/v2\/categories?post=116982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chkserv.com\/blog\/wp-json\/wp\/v2\/tags?post=116982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}