{"id":3968,"date":"2026-08-01T13:09:03","date_gmt":"2026-08-01T13:09:03","guid":{"rendered":"https:\/\/veerhost.com\/docs\/wordpress-3\/how-to-fix-error-establishing-a-database-connection-in-wordpress\/"},"modified":"2026-08-01T13:11:17","modified_gmt":"2026-08-01T13:11:17","slug":"how-to-fix-error-establishing-a-database-connection-in-wordpress","status":"publish","type":"docs","link":"https:\/\/veerhost.com\/de\/docs\/wordpress-3\/how-to-fix-error-establishing-a-database-connection-in-wordpress\/","title":{"rendered":"How to Fix &#8220;Error Establishing a Database Connection&#8221; in WordPress"},"content":{"rendered":"<p class=\"wp-block-paragraph\">The <strong>&#8220;Error Establishing a Database Connection&#8221;<\/strong> message indicates that WordPress cannot communicate with its database. Since WordPress stores your website&#8217;s content, settings, users, and configuration data in a database, the website cannot function until the connection is restored.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains the most common causes of the error and provides step-by-step troubleshooting methods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Symptoms<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You may notice one or more of the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Your website displays <strong>&#8220;Error Establishing a Database Connection.&#8221;<\/strong><\/li>\n\n\n\n<li>The WordPress admin dashboard is inaccessible.<\/li>\n\n\n\n<li>Visitors cannot access your website.<\/li>\n\n\n\n<li>The error appears immediately after updating WordPress, migrating your website, or changing hosting providers.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Common Causes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The most common reasons include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Incorrect database credentials<\/li>\n\n\n\n<li>Corrupted database<\/li>\n\n\n\n<li>Database server is unavailable<\/li>\n\n\n\n<li>Corrupted <code>wp-config.php<\/code><\/li>\n\n\n\n<li>Hosting server issues<\/li>\n\n\n\n<li>Exceeded database limits<\/li>\n\n\n\n<li>Corrupted WordPress files<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Before You Begin<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before making changes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a backup if possible.<\/li>\n\n\n\n<li>Verify you have access to your hosting control panel.<\/li>\n\n\n\n<li>Confirm you can access your website files.<\/li>\n\n\n\n<li>Have your database credentials available.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Check Your Database Credentials<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress stores its database connection details in the <code>wp-config.php<\/code> file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Verify the following values:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>define('DB_NAME', 'database_name');\ndefine('DB_USER', 'database_user');\ndefine('DB_PASSWORD', 'database_password');\ndefine('DB_HOST', 'localhost');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ensure that:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Database name is correct.<\/li>\n\n\n\n<li>Database username is correct.<\/li>\n\n\n\n<li>Password matches the database user.<\/li>\n\n\n\n<li>Database host is correct.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Incorrect credentials are one of the most common causes of this error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Verify the Database Exists<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Using your hosting control panel:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open the MySQL Databases section.<\/li>\n\n\n\n<li>Confirm the database still exists.<\/li>\n\n\n\n<li>Verify the database user is assigned to the database.<\/li>\n\n\n\n<li>Ensure the user has <strong>All Privileges<\/strong>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If the database was accidentally deleted, restore it from a recent backup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Check the Database Server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes the database server is temporarily unavailable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Possible causes include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Server maintenance<\/li>\n\n\n\n<li>Database service restart<\/li>\n\n\n\n<li>High server load<\/li>\n\n\n\n<li>Hosting outage<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If multiple websites on the same hosting account experience the same issue, contact your hosting provider.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Repair the WordPress Database<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If the database has become corrupted, WordPress includes a built-in repair feature.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Enable Database Repair<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open <code>wp-config.php<\/code> and add:<\/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\">Save the file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then visit:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:&#47;&#47;yourdomain.com\/wp-admin\/maint\/repair.php<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Choose:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Repair Database<\/li>\n\n\n\n<li>Repair and Optimize Database<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">After the repair completes, remove the following line from <code>wp-config.php<\/code>:<\/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\">Leaving it enabled may expose the repair page to unauthorized visitors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Verify Database Host<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most hosting providers use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>localhost<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">However, some providers use a different hostname.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;re unsure, check your hosting documentation or contact your hosting provider.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Check Database User Permissions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The database user should have permission to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SELECT<\/li>\n\n\n\n<li>INSERT<\/li>\n\n\n\n<li>UPDATE<\/li>\n\n\n\n<li>DELETE<\/li>\n\n\n\n<li>CREATE<\/li>\n\n\n\n<li>ALTER<\/li>\n\n\n\n<li>INDEX<\/li>\n\n\n\n<li>DROP<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">If permissions are missing, reassign the user and grant <strong>All Privileges<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 7: Check Server Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Insufficient server resources can prevent database connections.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Review your hosting account for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Memory usage<\/li>\n\n\n\n<li>CPU usage<\/li>\n\n\n\n<li>Disk space<\/li>\n\n\n\n<li>Database limits<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Resource exhaustion is more common on shared hosting environments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 8: Restore a Recent Backup<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If the error occurred after:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Updating WordPress<\/li>\n\n\n\n<li>Installing a plugin<\/li>\n\n\n\n<li>Editing configuration files<\/li>\n\n\n\n<li>Migrating your website<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Restore your most recent working backup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 9: Verify WordPress Core Files<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Corrupted core files can sometimes contribute to connection issues.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If necessary:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Download the latest version of WordPress.<\/li>\n\n\n\n<li>Replace only the core files.<\/li>\n\n\n\n<li>Do not overwrite the <code>wp-content<\/code> directory or <code>wp-config.php<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Step 10: Contact Your Hosting Provider<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If all previous steps fail, your hosting provider can help determine whether the issue is related to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Database service failures<\/li>\n\n\n\n<li>Server outages<\/li>\n\n\n\n<li>Corrupted databases<\/li>\n\n\n\n<li>Account restrictions<\/li>\n\n\n\n<li>Resource limitations<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Provide them with the exact error message and any troubleshooting steps you have already completed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the Fix<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After resolving the issue:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Reload your website.<\/li>\n\n\n\n<li>Log in to the WordPress dashboard.<\/li>\n\n\n\n<li>Confirm posts and pages load correctly.<\/li>\n\n\n\n<li>Verify plugins and themes function normally.<\/li>\n\n\n\n<li>Review your website for any additional errors.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Common Scenarios<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Website Works but Admin Does Not<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Possible causes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Corrupted plugin<\/li>\n\n\n\n<li>Database table corruption<\/li>\n\n\n\n<li>User table issues<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Both Website and Admin Are Offline<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Usually caused by:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Incorrect database credentials<\/li>\n\n\n\n<li>Database server outage<\/li>\n\n\n\n<li>Corrupted database<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Error Appeared After Migration<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Verify:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Database import completed successfully.<\/li>\n\n\n\n<li><code>wp-config.php<\/code> contains the new database credentials.<\/li>\n\n\n\n<li>Database hostname matches your new hosting environment.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Error Appeared After Updating WordPress<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Try:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Restoring your latest backup.<\/li>\n\n\n\n<li>Checking database integrity.<\/li>\n\n\n\n<li>Verifying plugin compatibility.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create backups before making major changes.<\/li>\n\n\n\n<li>Keep WordPress updated.<\/li>\n\n\n\n<li>Use reliable hosting.<\/li>\n\n\n\n<li>Monitor server resources.<\/li>\n\n\n\n<li>Store database credentials securely.<\/li>\n\n\n\n<li>Test backups regularly.<\/li>\n\n\n\n<li>Review database permissions periodically.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What causes &#8220;Error Establishing a Database Connection&#8221;?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The error usually occurs because WordPress cannot connect to its database due to incorrect credentials, database corruption, server outages, or configuration issues.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Will I lose my website data?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Not necessarily. In most cases, your data still exists in the database, but WordPress is temporarily unable to access it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can plugins cause this error?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Plugins rarely cause the error directly, but an incompatible plugin or failed update can contribute to database issues or configuration changes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I reinstall WordPress?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Reinstalling WordPress should only be considered after verifying that your database credentials, database server, and configuration files are correct.<\/p>","protected":false},"excerpt":{"rendered":"<p>The &#8220;Error Establishing a Database Connection&#8221; message indicates that WordPress cannot communicate with its database. Since WordPress stores your website&#8217;s content, settings, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3952,"menu_order":6,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-3968","docs","type-docs","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/3968","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=3968"}],"version-history":[{"count":1,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/3968\/revisions"}],"predecessor-version":[{"id":3970,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/3968\/revisions\/3970"}],"up":[{"embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/3952"}],"wp:attachment":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/media?parent=3968"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/doc_tag?post=3968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}