{"id":9168,"date":"2026-07-13T08:03:49","date_gmt":"2026-07-13T02:33:49","guid":{"rendered":"https:\/\/www.veeble.com\/kb\/?p=9168"},"modified":"2026-07-13T08:03:49","modified_gmt":"2026-07-13T02:33:49","slug":"error-establishing-a-database-connection","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/error-establishing-a-database-connection\/","title":{"rendered":"Error Establishing a Database Connection: How to Fix It (2026 Guide)"},"content":{"rendered":"\n<div class=\"wp-block-uagb-image uagb-block-f482a281 wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-none\"><figure class=\"wp-block-uagb-image__figure\"><a class=\"\" href=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/07\/Screenshot-2026-07-13-073237.jpg\" target=\"\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/07\/Screenshot-2026-07-13-073237-1024x536.jpg\" alt=\"\" class=\"uag-image-9171\" width=\"616\" height=\"322\" title=\"Screenshot 2026-07-13 073237\" loading=\"lazy\" role=\"img\" \/><\/a><\/figure><\/div>\n\n\n\n<div style=\"height:23px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Error establishing a database connection<\/strong> is a common WordPress error that prevents your website from loading. Instead of your homepage or the WordPress admin dashboard, you&#8217;ll only see a message saying that WordPress couldn&#8217;t connect to the database.<\/p>\n\n\n\n<p>In most cases, the problem is caused by incorrect database credentials, a database server issue, or a corrupted database. The good news is that it&#8217;s usually straightforward to fix once you identify the cause.<\/p>\n\n\n\n<p>This guide walks through the most common causes first, so you can start with the fixes that resolve this error for most WordPress sites.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#what-causes-this-error\">What Causes This Error<\/a><\/li><li><a href=\"#before-you-start-take-a-backup\">Before You Start: Take a Backup<\/a><\/li><li><a href=\"#fix-1-check-your-database-credentials-in-wp-config-php\">Fix 1: Check Your Database Credentials in wp-config.php<\/a><\/li><li><a href=\"#fix-2-test-the-database-connection-directly\">Fix 2: Test the Database Connection Directly<\/a><\/li><li><a href=\"#fix-3-reset-the-database-user-password\">Fix 3: Reset the Database User Password<\/a><\/li><li><a href=\"#fix-4-confirm-the-database-user-has-full-privileges\">Fix 4: Confirm the Database User Has Full Privileges<\/a><\/li><li><a href=\"#fix-5-check-if-my-sql-or-maria-db-is-actually-running\">Fix 5: Check If MySQL or MariaDB Is Actually Running<\/a><\/li><li><a href=\"#fix-6-repair-a-corrupted-database\">Fix 6: Repair a Corrupted Database<\/a><\/li><li><a href=\"#fix-7-rule-out-a-connection-limit-problem\">Fix 7: Rule Out a Connection Limit Problem<\/a><\/li><li><a href=\"#preventing-this-error-in-the-future\">Preventing This Error in the Future<\/a><\/li><li><a href=\"#conclusion\">Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"what-causes-this-error\">What Causes This Error<\/h2>\n\n\n<p>WordPress connects to your database using the details stored in <code>wp-config.php<\/code>. These include the database name, username, password, and database host. If any of these values are incorrect, or if the database server isn&#8217;t responding, WordPress won&#8217;t be able to establish a connection. Below are the most common causes of this error, starting with the ones seen most often.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Incorrect database credentials in <code>wp-config.php<\/code><\/strong>. This is the most common cause, especially after migrating a website or moving it to a new hosting provider.<\/li>\n\n\n\n<li><strong>An incorrect <code>DB_HOST<\/code> value<\/strong>. Most WordPress sites use <code>localhost<\/code>, but some hosting providers use a different database host.<\/li>\n\n\n\n<li><strong>The MySQL or MariaDB service is unavailable<\/strong>. This can happen if the database service has stopped, is overloaded, or the server is experiencing high resource usage.<\/li>\n\n\n\n<li><strong>A corrupted database<\/strong>. Interrupted updates, failed migrations, or faulty plugins can sometimes corrupt one or more database tables.<\/li>\n\n\n\n<li><strong>Missing database user privileges<\/strong>. If the database or user was recreated, the user may no longer have permission to access the database.<\/li>\n\n\n\n<li><strong>The database has reached its connection limit<\/strong>. This usually happens during periods of high traffic or when too many connections are left open.<\/li>\n<\/ol>\n\n\n\n<p>Work through the fixes below in order. In most cases, the problem is resolved by checking the database credentials or confirming that the database server is running.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"before-you-start-take-a-backup\">Before You Start: Take a Backup<\/h2>\n\n\n<p>Before editing <code>wp-config.php<\/code> or making changes to the database, create a backup if possible. If your site is already offline, check whether a recent automatic backup is available through your hosting provider.<br><br>A recent backup makes it much easier to recover your website if any changes need to be rolled back.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"fix-1-check-your-database-credentials-in-wp-config-php\">Fix 1: Check Your Database Credentials in wp-config.php<\/h2>\n\n\n<p>Open the <code>wp-config.php<\/code> file using cPanel&#8217;s <strong>File Manager<\/strong> or an SFTP client. This file is located in the root directory of your WordPress installation.<\/p>\n\n\n\n<p>Find the following lines:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-ast-global-color-0-background-color has-text-color has-background has-link-color wp-elements-31eb22fadf4cba1a82689bd6a509a5c7\"><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>Next, verify that each value matches your actual database configuration.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log into cPanel and open <strong>MySQL Databases<\/strong> under the Databases section.<\/li>\n\n\n\n<li>Under <strong>Current Databases<\/strong>, confirm the DB_NAME value matches an existing database.<\/li>\n\n\n\n<li>Under <strong>Current Users<\/strong>, confirm the DB_USER value matches an existing MySQL user.<\/li>\n\n\n\n<li>If the password is wrong or you&#8217;re not sure what it is, skip to Fix 3.<\/li>\n<\/ol>\n\n\n\n<p>Even a small typo in the database name, username, password, or host can prevent WordPress from connecting to the database. If you find any incorrect values, update <code>wp-config.php<\/code>, save the file, and reload your website.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"fix-2-test-the-database-connection-directly\">Fix 2: Test the Database Connection Directly<\/h2>\n\n\n<p>If the credentials in wp-config.php look correct but the error persists, test the connection outside of WordPress to see the real error message instead of WordPress&#8217;s generic one.<\/p>\n\n\n\n<p><strong>With WP-CLI (if you have SSH access):<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-color has-ast-global-color-0-background-color has-text-color has-background has-link-color wp-elements-3fc3ba65d6931a500be28f749806b871\"><code>wp db check --debug<\/code><\/pre>\n\n\n\n<p>A working connection returns <code>Success: Database checked.<\/code> A broken one returns something specific, such as <code>Access denied for user<\/code>, which points to a credentials problem, or <code>Unknown MySQL server host<\/code>, which points to a wrong DB_HOST value.<\/p>\n\n\n\n<p><strong>Without SSH access<\/strong>, create a test file in your site&#8217;s root folder:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-color has-ast-global-color-0-background-color has-text-color has-background has-link-color wp-elements-51a0c6d2ad3f0c789d37c47d0b715c79\"><code>&lt;?php\n$test = mysqli_connect('localhost', 'db_user', 'db_password');\nif (!$test) {\n    die('MySQL Error: ' . mysqli_connect_error());\n}\necho 'Database connection is working properly!';\nmysqli_close($test);<\/code><\/pre>\n\n\n\n<p>Replace <code>db_user<\/code> and <code>db_password<\/code> with the values from <code>wp-config.php<\/code>, then visit <code>https:\/\/yourdomain.com\/checkdb.php<\/code> in your browser. If you receive an <strong>Access denied<\/strong> error, verify your database username and password.<\/p>\n\n\n\n<p>Delete the <code>checkdb.php<\/code> file as soon as you&#8217;ve finished testing. It contains database connection details and should not be left accessible on your server.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"fix-3-reset-the-database-user-password\">Fix 3: Reset the Database User Password<\/h2>\n\n\n<p>If you&#8217;re not sure what the current database password is, or Fix 2 confirmed the credentials are wrong, reset it rather than guessing.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In cPanel, go to <strong>MySQL Databases<\/strong>.<\/li>\n\n\n\n<li>Scroll to <strong>Current Users<\/strong> and find the user matching your DB_USER value.<\/li>\n\n\n\n<li>Click <strong>Change Password<\/strong>, set a new strong password, and save it.<\/li>\n\n\n\n<li>Update DB_PASSWORD in wp-config.php to match.<\/li>\n\n\n\n<li>Save the file and reload your site.<\/li>\n<\/ol>\n\n\n<h2 class=\"wp-block-heading\" id=\"fix-4-confirm-the-database-user-has-full-privileges\">Fix 4: Confirm the Database User Has Full Privileges<\/h2>\n\n\n<p>A database user without the correct privileges can authenticate successfully but still fail to read or write data, which produces the same error. This usually happens after a database is recreated or a user is added without being linked to it.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In cPanel, go to <strong>MySQL Databases<\/strong>.<\/li>\n\n\n\n<li>Scroll to <strong>Add User to Database<\/strong>.<\/li>\n\n\n\n<li>Select the correct user and database from the dropdowns and click <strong>Add<\/strong>.<\/li>\n\n\n\n<li>On the next screen, select <strong>All Privileges<\/strong> and click <strong>Make Changes<\/strong>.<\/li>\n<\/ol>\n\n\n<h2 class=\"wp-block-heading\" id=\"fix-5-check-if-my-sql-or-maria-db-is-actually-running\">Fix 5: Check If MySQL or MariaDB Is Actually Running<\/h2>\n\n\n<p>On shared hosting, the database service is managed for you, so if Fixes 1 through 4 don&#8217;t resolve it, contact support and ask them to confirm the MySQL service status on your account.<\/p>\n\n\n\n<p>On a VPS or dedicated server where you manage the stack yourself, check the service directly:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-color has-ast-global-color-0-background-color has-text-color has-background has-link-color wp-elements-7b6874ff90389334ee42a130db505b5b\"><code>systemctl status mysql<\/code><\/pre>\n\n\n\n<p>or, on servers running MariaDB:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-color has-ast-global-color-0-background-color has-text-color has-background has-link-color wp-elements-436855fa35a8473b9a12ad56eed674f2\"><code>systemctl status mariadb<\/code><\/pre>\n\n\n\n<p>If the service shows as inactive or failed, start it:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-color has-ast-global-color-0-background-color has-text-color has-background has-link-color wp-elements-1fe4eca510dab4e157786ba57056627d\"><code>sudo systemctl start mysql<\/code><\/pre>\n\n\n\n<p>Check the error log for the reason it stopped, since a repeated crash often points to memory exhaustion rather than a one-off issue:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-color has-ast-global-color-0-background-color has-text-color has-background has-link-color wp-elements-dcdf82e857e0b63ba68b1b4d0d229e3a\"><code>sudo tail -n 50 \/var\/log\/mysql\/error.log<\/code><\/pre>\n\n\n\n<p>If the log shows the service being killed repeatedly under load, the server needs more available memory, not just a restart.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"fix-6-repair-a-corrupted-database\">Fix 6: Repair a Corrupted Database<\/h2>\n\n\n<p>If wp-admin shows a different message, such as &#8220;One or more database tables are unavailable&#8221; or &#8220;The database may need to be repaired,&#8221; the tables themselves are damaged rather than the connection. Don&#8217;t apply credential fixes for this, use the repair tool instead.<\/p>\n\n\n\n<p><strong>With WP-CLI:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-color has-ast-global-color-0-background-color has-text-color has-background has-link-color wp-elements-dbd0a4841cb63cb55f0a4132c8e07014\"><code>wp db repair<\/code><\/pre>\n\n\n\n<p><strong>Without SSH access<\/strong>, add this line to wp-config.php, above the line that says &#8220;That&#8217;s all, stop editing&#8221;:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-color has-ast-global-color-0-background-color has-text-color has-background has-link-color wp-elements-b0e57249b5ce9f7651e0e1fe8ef7277a\"><code>define( 'WP_ALLOW_REPAIR', true );<\/code><\/pre>\n\n\n\n<p>Then visit <code>https:\/\/yourdomain.com\/wp-admin\/maint\/repair.php<\/code> and click <strong>Repair Database<\/strong>. Once the process finishes, remove the line from wp-config.php immediately. The repair page has no login requirement while that line is present, so leaving it in place is a security risk.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"fix-7-rule-out-a-connection-limit-problem\">Fix 7: Rule Out a Connection Limit Problem<\/h2>\n\n\n<p>If the error only occurs occasionally, especially during periods of high traffic, your database server may have reached its maximum connection limit. This is more common on shared hosting, where multiple websites share the same server resources.<\/p>\n\n\n\n<p>In this case, checking your database credentials or editing <code>wp-config.php<\/code> won&#8217;t resolve the issue. Instead, you need to reduce the number of simultaneous database connections or increase the available server resources.<\/p>\n\n\n\n<p>Using a caching plugin can significantly reduce database load. If your website regularly reaches the connection limit, consider upgrading to a <a href=\"https:\/\/www.veeble.com\/vps-hosting\/\" target=\"_blank\" rel=\"noreferrer noopener\">VPS hosting<\/a> plan, where your database has dedicated resources and isn&#8217;t affected by other accounts on the same server.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"preventing-this-error-in-the-future\">Preventing This Error in the Future<\/h2>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Document your database credentials somewhere secure<\/strong> whenever you set up a new site or migrate one, so you&#8217;re not reconstructing them under pressure during an outage.<\/li>\n\n\n\n<li><strong>Double-check DB_HOST specifically after any migration.<\/strong> It&#8217;s the value people forget most often since it&#8217;s easy to assume &#8220;localhost&#8221; carries over.<\/li>\n\n\n\n<li><strong>Run <code>wp db check<\/code> after migrations<\/strong>, before you consider the job done, to catch a bad connection while you still have the old environment to compare against.<\/li>\n\n\n\n<li><strong>Keep recent backups<\/strong>, ideally automated, so a corrupted database is a restore instead of a rebuild.<\/li>\n\n\n\n<li><strong>Monitor server resource usage<\/strong> if you&#8217;re on a VPS or dedicated server, since memory exhaustion is a common reason MySQL gets killed and restarted unexpectedly.<\/li>\n<\/ul>\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n<p><strong>Error establishing a database connection<\/strong> is usually caused by incorrect database credentials, a database service issue, or a corrupted database. Start by checking the settings in <code>wp-config.php<\/code>, then work through the remaining fixes until the connection is restored.<\/p>\n\n\n\n<p>If you need assistance troubleshooting database or server issues, a <a href=\"https:\/\/www.veeble.com\/cpanel-hosting\/\" target=\"_blank\" rel=\"noreferrer noopener\">cPanel hosting<\/a> plan gives you access to the tools needed to manage your website, along with support when server-side issues require further investigation.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Error establishing a database connection is a common WordPress error that prevents your website from loading. Instead of your homepage or the WordPress admin [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":9171,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[4,5,11],"tags":[34,101,65,80,86,102,78],"class_list":["post-9168","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cpanel","category-linux","category-mysql","tag-cpanel","tag-database-errors","tag-mysql","tag-shared-hosting","tag-troubleshooting","tag-website-errors","tag-wordpress"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/07\/Screenshot-2026-07-13-073237.jpg",1432,750,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/07\/Screenshot-2026-07-13-073237-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/07\/Screenshot-2026-07-13-073237-300x157.jpg",300,157,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/07\/Screenshot-2026-07-13-073237-768x402.jpg",768,402,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/07\/Screenshot-2026-07-13-073237-1024x536.jpg",1024,536,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/07\/Screenshot-2026-07-13-073237.jpg",1432,750,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2026\/07\/Screenshot-2026-07-13-073237.jpg",1432,750,false]},"uagb_author_info":{"display_name":"Nasarul Naseer","author_link":"https:\/\/www.veeble.com\/kb\/author\/nasarulnaseer\/"},"uagb_comment_info":0,"uagb_excerpt":"Error establishing a database connection is a common WordPress error that prevents your website from loading. Instead of your homepage or the WordPress admin [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/9168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=9168"}],"version-history":[{"count":4,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/9168\/revisions"}],"predecessor-version":[{"id":9173,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/9168\/revisions\/9173"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/9171"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=9168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=9168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=9168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}