{"id":2299,"date":"2026-03-31T17:43:23","date_gmt":"2026-03-31T17:43:23","guid":{"rendered":"https:\/\/veerhost.com\/docs\/fix-wordpress-error-establishing-a-database-connection\/"},"modified":"2026-07-02T23:05:59","modified_gmt":"2026-07-02T23:05:59","slug":"fix-wordpress-error-establishing-a-database-connection","status":"publish","type":"docs","link":"https:\/\/veerhost.com\/de\/docs\/getting-started\/fix-wordpress-error-establishing-a-database-connection\/","title":{"rendered":"Fix: WordPress Error Establishing a Database Connection"},"content":{"rendered":"<p class=\"wp-block-paragraph\">The &#8220;Error Establishing a Database Connection&#8221; screen means WordPress can&#8217;t connect to its MySQL database. Here are all the common causes and fixes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Cause 1: Wrong Credentials in wp-config.php<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The credentials in <code>wp-config.php<\/code> must match exactly what&#8217;s set in cPanel. Log in to cPanel \u2192 <strong>File Manager<\/strong> \u2192 open your site&#8217;s root folder \u2192 edit <code>wp-config.php<\/code> and verify:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>define( 'DB_NAME',     'your_database_name' );\ndefine( 'DB_USER',     'your_database_user' );\ndefine( 'DB_PASSWORD', 'your_database_password' );\ndefine( 'DB_HOST',     'localhost' );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To confirm the correct values, go to cPanel \u2192 <strong>MySQL Databases<\/strong> and check the database name, username, and that the user has <strong>ALL PRIVILEGES<\/strong> on the database. If the password is wrong, reset it there and update <code>wp-config.php<\/code> to match.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Cause 2: Database User Not Assigned to the Database<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In cPanel \u2192 <strong>MySQL Databases<\/strong>, scroll down to <strong>Add User To Database<\/strong>. Make sure your database user is assigned and has <strong>ALL PRIVILEGES<\/strong>. This step is easy to miss when creating a new database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Cause 3: Corrupted Database Tables<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If credentials are correct but the error persists, the database tables may be corrupted. Add this line to <code>wp-config.php<\/code> (above the <code>\/* That's all, stop editing! *\/<\/code> line):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>define( 'WP_ALLOW_REPAIR', true );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then visit <code>https:\/\/yourdomain.com\/wp-admin\/maint\/repair.php<\/code> and click <strong>Repair Database<\/strong>. <strong>Remove that line from wp-config.php immediately after<\/strong> \u2014 it&#8217;s a security risk to leave it active.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Cause 4: Restore From a Backup<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If the database is too damaged to repair, restore from a recent backup. In cPanel \u2192 <strong>Backup Wizard<\/strong> \u2192 <strong>Restore<\/strong> \u2192 <strong>MySQL Database<\/strong>, upload your latest <code>.sql.gz<\/code> backup file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Don&#8217;t have a backup? See <a href=\"https:\/\/veerhost.com\/de\/docs\/getting-started\/how-to-back-up-your-website-in-cpanel\/\">How to Back Up Your Website in cPanel<\/a> to set one up now.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Still Getting the Error?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Contact Veerhost support at <a href=\"https:\/\/veerhost.com\/de\/support\/\">veerhost.com\/support<\/a> with your domain name. Our team can check MySQL server status and assist with database recovery.<\/p>","protected":false},"excerpt":{"rendered":"<p>The &#8220;Error Establishing a Database Connection&#8221; screen means WordPress can&#8217;t connect to its MySQL database. Here are all the common causes and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1894,"menu_order":6,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-2299","docs","type-docs","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/2299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/comments?post=2299"}],"version-history":[{"count":1,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/2299\/revisions"}],"predecessor-version":[{"id":2300,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/2299\/revisions\/2300"}],"up":[{"embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/1894"}],"wp:attachment":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/media?parent=2299"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/doc_tag?post=2299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}