{"id":6536,"date":"2025-11-24T03:59:05","date_gmt":"2025-11-24T03:59:05","guid":{"rendered":"https:\/\/youstable.com\/kb\/?p=6536"},"modified":"2025-11-24T03:59:07","modified_gmt":"2025-11-24T03:59:07","slug":"error-establishing-database-connection","status":"publish","type":"post","link":"https:\/\/www.youstable.com\/blog\/error-establishing-database-connection","title":{"rendered":"How to resolve &#8220;Error Establishing Database Connection&#8221; in WordPress"},"content":{"rendered":"\n<p>You are opening your WordPress website and getting a message stating &#8220;<strong>Error Establishing Database Connection &#8220;<\/strong>, reasons may be one of the following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1164\" height=\"492\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-69.png\" alt=\"How to resolve \u201cError Establishing Database Connection\u201d in WordPress\" class=\"wp-image-6560\" srcset=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-69.png 1164w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-69-768x325.png 768w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-69-810x342.png 810w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-69-1140x482.png 1140w\" sizes=\"auto, (max-width: 1164px) 100vw, 1164px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>The database has been corrupted.<\/li><li>The database login credentials given in wp-config.php are wrong<\/li><li>The WordPress database tables have been corrupted or not imported properly.<\/li><li>The table prefix is wrong.<\/li><\/ul>\n\n\n\n<p>Here, we will learn How to fix <strong>Error Establishing Database Connection<\/strong> for your WordPress-based Website.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-1-check-database-login-credentials\">Step 1 \u2014 Check Database Login Credentials<\/h3>\n\n\n\n<p>You&#8217;ve just migrated your WordPress-based website from previous hosting providers to elsewhere; you need to update your database connection details given in wp-config.php.<\/p>\n\n\n\n<p>Click here to learn how to Edit the wp-config.php file in <strong><a href=\"https:\/\/youstable.com\/blog\/edit-wp-config-php\/\" target=\"_blank\" rel=\"noopener\">DirectAdmin<\/a> <\/strong>or <a href=\"https:\/\/youstable.com\/blog\/edit-wp-config-php-file\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>cPanel<\/strong><\/a>.<\/p>\n\n\n\n<p>Locate the database connection information given in your config file.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/** The name of the database for WordPress *\/\ndefine(&#039;DB_NAME&#039;, &#039;database_name&#039;);\n\n\/** MySQL database username *\/\ndefine(&#039;DB_USER&#039;, &#039;database_username&#039;);\n\n\/** MySQL database password *\/\ndefine(&#039;DB_PASSWORD&#039;, &#039;database_password&#039;);\n<\/pre><\/div>\n\n\n<p>Check the connection details as mentioned with correct details. If the connection detail is wrong, please update the information, click Save, and exit.<\/p>\n\n\n\n<p>Reload the website to check if the issue is resolved or not.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-2-check-the-table-prefix\"><strong>Step 2 \u2014 Check the table prefix<\/strong><\/h3>\n\n\n\n<p>Open PHPMyAdmin and click on your database.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-3-1.png\" alt=\"\" class=\"wp-image-6565\" width=\"603\" height=\"282\" srcset=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-3-1.png 952w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-3-1-768x360.png 768w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-3-1-810x379.png 810w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/figure>\n\n\n\n<p>Check the prefix given before the table name. The table prefix is given in wp-config.php, and the one showing in PHPMyAdmin must be the same.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"465\" height=\"447\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-4-1.png\" alt=\"\" class=\"wp-image-6571\"><figcaption>table_prefix in PHPMyAdmin<\/figcaption><\/figure>\n\n\n\n<p> <\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-6-1.png\" alt=\"\" class=\"wp-image-6577\" width=\"497\" height=\"254\"><figcaption>table_prefix in wp-config.php<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-3-try-repairing-the-wordpress-database\">Step 3 \u2014 Try repairing the WordPress Database<\/h3>\n\n\n\n<p>cPanel provides you with the feature of a repair database. Please follow the steps below to repair the database.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"through-cpanel\"><strong>Through cPanel<\/strong><\/h4>\n\n\n\n<p><strong>1. <\/strong><a href=\"https:\/\/youstable.com\/blog\/how-to-login-to-cpanel\/\" target=\"_blank\" rel=\"noopener\">Login into cPanel<\/a>.<\/p>\n\n\n\n<p><strong>2.<\/strong> Navigate to the <strong>DATABASE <\/strong>section and click on <strong>MySQL\u00ae Databases<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-7-1.png\" alt=\"\" class=\"wp-image-6578\" width=\"674\" height=\"233\" srcset=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-7-1.png 1024w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-7-1-768x266.png 768w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-7-1-810x280.png 810w\" sizes=\"auto, (max-width: 674px) 100vw, 674px\" \/><\/figure>\n\n\n\n<p><strong>3.<\/strong> Go to the <strong>Modify Databases<\/strong> section, select your database from the drop-down, and click on <strong>Repair Database.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1440\" height=\"474\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-8-1.png\" alt=\"Modify databases\" class=\"wp-image-6579\" srcset=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-8-1.png 1440w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-8-1-768x253.png 768w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-8-1-810x267.png 810w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-8-1-1140x375.png 1140w\" sizes=\"auto, (max-width: 1440px) 100vw, 1440px\" \/><\/figure>\n\n\n\n<p><strong>4. <\/strong>A new GUI will appear, and the system will attempt to check\/repair the database automatically.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"through-phpmyadmin\"><strong>Through PHPMyAdmin<\/strong><\/h4>\n\n\n\n<p>We can repair our database using PHPMyAdmin too. Let&#8217;s see how to repair the database using PHPMyAdmin.<\/p>\n\n\n\n<p><strong>1. <\/strong><a href=\"https:\/\/youstable.com\/kb\/2022\/02\/22\/how-to-login-to-cpanel\/\" target=\"_blank\" rel=\"noopener\">Login into cPanel<\/a>.<\/p>\n\n\n\n<p><strong>2.<\/strong> Navigate to the <strong>DATABASE <\/strong>section and click on <strong>phpMyAdmin.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1244\" height=\"364\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-9-1.png\" alt=\"cpanle phpmyadmin\" class=\"wp-image-6582\" srcset=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-9-1.png 1244w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-9-1-768x225.png 768w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-9-1-810x237.png 810w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-9-1-1140x334.png 1140w\" sizes=\"auto, (max-width: 1244px) 100vw, 1244px\" \/><\/figure>\n\n\n\n<p><strong>3.<\/strong> PHPMyAdmin will open in a new tab of your browser. Click on the database which you want to repair.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"949\" height=\"440\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-10-1.png\" alt=\"\" class=\"wp-image-6584\" srcset=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-10-1.png 949w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-10-1-768x356.png 768w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-10-1-810x376.png 810w\" sizes=\"auto, (max-width: 949px) 100vw, 949px\" \/><\/figure>\n\n\n\n<p><strong>4.<\/strong> If you are sure about the table causing the issue, you can select the table or check all the tables for repair.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1363\" height=\"741\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-12-1.png\" alt=\"\" class=\"wp-image-6586\" srcset=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-12-1.png 1363w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-12-1-768x418.png 768w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-12-1-810x440.png 810w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-12-1-1140x620.png 1140w\" sizes=\"auto, (max-width: 1363px) 100vw, 1363px\" \/><\/figure>\n\n\n\n<p><strong>5.<\/strong> From the drop-down\u00a0<strong>With selected:\u00a0<\/strong>choose\u00a0<strong><em>Repair\u00a0table<\/em><\/strong>. This will execute the\u00a0<em>REPAIR TABLE<\/em>\u00a0SQL query on the selected tables or all tables if you have selected <em>Check All,<\/em> and the tables will be checked or repaired.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1363\" height=\"741\" src=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-13-1.png\" alt=\"\" class=\"wp-image-6587\" srcset=\"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-13-1.png 1363w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-13-1-768x418.png 768w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-13-1-810x440.png 810w, https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/image-13-1-1140x620.png 1140w\" sizes=\"auto, (max-width: 1363px) 100vw, 1363px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"through-wp-config-php\"><strong>Through wp-config.php<\/strong><\/h4>\n\n\n\n<p>WordPress provides built-in functions to repair the database, which is disabled by default due to a security issue.<\/p>\n\n\n\n<p>Here, we will learn how to enable the feature, run the repairs, and then disable it to avoid this potential security threat.<\/p>\n\n\n\n<p>Open the wp-config.php file and paste the following code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\ndefine(&#039;WP_ALLOW_REPAIR&#039;, true);\n<\/pre><\/div>\n\n\n<p>Save and close the editor.<\/p>\n\n\n\n<p>Open the browser and load the following address.<\/p>\n\n\n\n<p><em>Note: Please replace yourdomain.com with your actual domain name<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">http:\/\/www.yourdomain.com\/wp-admin\/maint\/repair.php<\/pre>\n\n\n\n<p>Press the&nbsp;<strong>Repair Database<\/strong>&nbsp;button, which will appear at page load.<\/p>\n\n\n\n<p>You&#8217;ll be taken to a results page where you can see the checks and repairs happening in real-time.<\/p>\n\n\n\n<p>After finishing the process, please open the wp-config.php file again and remove the line of code that we have pasted to disable the repair function.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>If your issue is still not resolved after following the steps given above, please restore your database from the old backup you have.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You are opening your WordPress website and getting a message stating &#8220;Error Establishing Database Connection &#8220;, reasons may be one [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6816,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"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":"","ast-disable-related-posts":"","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":"default","ast-page-background-enabled":"default","ast-page-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":"","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-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":"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":""},"mobile":{"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":""}},"footnotes":""},"categories":[1195],"tags":[],"class_list":["post-6536","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogging"],"acf":[],"featured_image_src":"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2022\/02\/How-to-resolve-Error-Establishing-Database-Connection-in-WordPress-01.jpg","author_info":{"display_name":"YouStable","author_link":"https:\/\/www.youstable.com\/blog\/author\/youstable"},"_links":{"self":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/6536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/comments?post=6536"}],"version-history":[{"count":2,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/6536\/revisions"}],"predecessor-version":[{"id":15792,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/6536\/revisions\/15792"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media\/6816"}],"wp:attachment":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media?parent=6536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/categories?post=6536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/tags?post=6536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}