{"id":33147,"date":"2021-08-13T12:27:39","date_gmt":"2021-08-13T06:42:39","guid":{"rendered":"https:\/\/rarathemes.com\/blog\/?p=33147"},"modified":"2022-01-03T10:59:27","modified_gmt":"2022-01-03T05:14:27","slug":"fix-error-establishing-database-connection","status":"publish","type":"post","link":"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/","title":{"rendered":"How to Fix &#8220;Error Establishing a Database Connection&#8221; in WordPress"},"content":{"rendered":"\n<p>Sometimes your website loses connection with your WordPress database. As a result, you see a blank white screen with the message \u201cError establishing a database connection.\u201d&nbsp;<\/p>\n\n\n\n<p>There may be many reasons behind this connection loss.<\/p>\n\n\n\n<p>It is one of the common errors in WordPress and is totally solvable.&nbsp;<\/p>\n\n\n\n<p>In this guide, you will learn what the \u201cError establishing a database connection is,\u201d the possible causes, and various ways to fix it.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#What_is_the_%E2%80%9CError_Establishing_a_Database_Connection%E2%80%9D_in_WordPress\" >What is the \u201cError Establishing a Database Connection\u201d in WordPress<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#Common_Causes_of_Error_Establishing_a_Database_Connection\" >Common Causes of Error Establishing a Database Connection<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#1_Incorrect_Credentials\" >1. Incorrect Credentials<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#2_Corrupted_WordPress_Files\" >2. Corrupted WordPress Files&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#3_Corrupted_Database\" >3. Corrupted Database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#4_Server_Issue\" >4. Server Issue<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#5_Too_Much_Traffic\" >5. Too Much Traffic&nbsp;<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#How_to_Fix_it\" >How to Fix it?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#Fix_1_Check_Your_Database_Credentials\" >Fix 1: Check Your Database Credentials&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#Fix_2_Confirm_Your_Database_Host_Information\" >Fix 2: Confirm Your Database Host Information<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#Fix_3_Repairing_Your_WordPress_Database\" >Fix 3: Repairing Your WordPress Database&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#Fix_4_Fixing_the_Corrupt_WordPress_Database_Files\" >Fix 4: Fixing the Corrupt WordPress Database Files&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#Fix_5_Check_if_the_Database_Server_is_Down\" >Fix 5: Check if the Database Server is Down<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#Other_Possible_Fix_for_the_%E2%80%9CError_Establishing_a_Database_Connection%E2%80%9D\" >Other Possible Fix for the \u201cError Establishing a Database Connection\u201d&nbsp;<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#1_Updating_the_WordPress_Site_URL\" >1. Updating the WordPress Site URL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#2_Reboot_the_Web_Server\" >2. Reboot the Web Server&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#3_Reach_Out_for_Technical_Support\" >3. Reach Out for Technical Support&nbsp;<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/rarathemes.com\/blog\/fix-error-establishing-database-connection\/#Conclusion\" >Conclusion&nbsp;<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_the_%E2%80%9CError_Establishing_a_Database_Connection%E2%80%9D_in_WordPress\"><\/span>What is the \u201cError Establishing a Database Connection\u201d in WordPress<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Understanding this error is not a jigsaw puzzle. The error is self-explanatory. Here is what it means in detail:&nbsp;<\/p>\n\n\n\n<p>WordPress uses PHP and MySQL to function.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>PHP<\/strong>: It is a programming language used to write the core WordPress files.&nbsp;<\/li><li><strong>MySQL<\/strong>: It is a database that stores your site\u2019s content, including pages, posts, layout, and all the settings. Basically, MySQL is the locker with all the elements of your website.<\/li><\/ul>\n\n\n\n<p>When a visitor lands on your website, WordPress executes PHP lines of commands to connect to MySQL. It then displays everything on the screen.&nbsp;<\/p>\n\n\n\n<p>When this connection breaks for some reason, WordPress cannot obtain information from the database to render on the screen. Thus, you are left with a blank white screen with the message \u201cError establishing a database connection\u201d as below:&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"342\" src=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/Error-Establishing-a-Database-Connection-Example.png\" alt=\"Error Establishing a Database Connection Example\" class=\"wp-image-33218\" srcset=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/Error-Establishing-a-Database-Connection-Example.png 700w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/Error-Establishing-a-Database-Connection-Example-300x147.png 300w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/Error-Establishing-a-Database-Connection-Example-123x60.png 123w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Common_Causes_of_Error_Establishing_a_Database_Connection\"><\/span>Common Causes of Error Establishing a Database Connection<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The gist is that the PHP command is not able to connect with MySQL. There are a handful of reasons that result in this connection breakage. Here are some of the common causes of this error:&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Incorrect_Credentials\"><\/span>1. Incorrect Credentials<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>WordPress needs specific credentials (username and password) to access the database. If the credentials you entered are wrong or mistyped, WordPress cannot fetch anything from your database. Thus, it shows the database connection error.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Corrupted_WordPress_Files\"><\/span>2. Corrupted WordPress Files&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Sometimes, your core WordPress files get corrupted due to failed plugin updates, themes, or the main WordPress software. This, too, can cause the database connection error.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Corrupted_Database\"><\/span>3. Corrupted Database<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Sometimes, a rogue plugin or a hacker\u2019s attack can mess up your database, leading to a database connection error.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Server_Issue\"><\/span>4. Server Issue<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The database connection error also shows up when the server that stores your WordPress files gets corrupted or malfunctions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Too_Much_Traffic\"><\/span>5. Too Much Traffic&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Even though more traffic is what every site owner wants, too high a spike in traffic can cause your database to become unresponsive. It happens when your post or page gets viral, and everyone is trying to access your website. Your server cannot handle the request, and you get the database connection error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Fix_it\"><\/span>How to Fix it?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Now that you know what this error is and what may cause it let\u2019s look at how to fix it. You can follow these five ways to try and fix this error:&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Fix_1_Check_Your_Database_Credentials\"><\/span>Fix 1: Check Your Database Credentials&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Incorrect database credential is the most common cause for the database connection error in WordPress. If you have recently moved to another host, this is probably the reason in your case.&nbsp;<\/p>\n\n\n\n<p>You can check the credentials in your wp-config.php file.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Log in to your site using an FTP client or a file manager.&nbsp;<\/li><\/ul>\n\n\n\n<p>Here is an example of accessing the site using FileZilla.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"445\" src=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/wp-config-file.png\" alt=\"access the wp-config file\" class=\"wp-image-33206\" srcset=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/wp-config-file.png 700w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/wp-config-file-300x191.png 300w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/wp-config-file-94x60.png 94w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/figure><\/div>\n\n\n\n<p>The right quadrants show the list of folders that contain your website\u2019s file.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Navigate down to your website\u2019s root folder. Mostly, the root folder is named after your domain name or public_html. Double click to open it.&nbsp;<\/li><li>Right-click the wp-config.php file and click on the \u2018Edit\u2019 option.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"448\" src=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/edit-wp-config.png\" alt=\"how to edit the wp-config\" class=\"wp-image-33208\" srcset=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/edit-wp-config.png 700w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/edit-wp-config-300x192.png 300w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/edit-wp-config-94x60.png 94w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/figure><\/div>\n\n\n\n<p>Now, look for the following four lines of information:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><em>Database Name&nbsp;<\/em><\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ ** MySQL settings ** \/\/\n\n\/** The name of the database for WordPress *\/\n\ndefine(\u2018DB_NAME', \u2018xxxxxx');<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><em>Database username<\/em><\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/** MySQL database username *\/\ndefine('DB_USER', 'xxxxxx');<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><em>Database password<\/em><\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/** MySQL database password *\/\n\ndefine(\u2018DB_PASSWORD', \u2018xxxxxxxxx');<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><em>Database hostname (server)<\/em><\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/** MySQL hostname *\/\n\ndefine(\u2018DB_HOST', \u2018localhost');<\/code><\/pre>\n\n\n\n<p>You need to make sure this information is correct. You can confirm this from your hosting account dashboard.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Log in to your hosting account.&nbsp;<\/li><li>Under the \u2018Database\u2019 section, click on the \u201cMySQL databases.\u201d&nbsp;<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"701\" height=\"362\" src=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-MySQL-database.png\" alt=\"accessing MySQL database\" class=\"wp-image-33213\" srcset=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-MySQL-database.png 701w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-MySQL-database-300x155.png 300w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-MySQL-database-116x60.png 116w\" sizes=\"auto, (max-width: 701px) 100vw, 701px\" \/><\/figure><\/div>\n\n\n\n<p><strong>Note<\/strong>: The dashboard may differ depending on your hosting provider.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You will land on the database management page. From here, you can find the database name and the database username.&nbsp;<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"284\" src=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/confirming-database-name-and-database-username.png\" alt=\"confirming database name and database username\" class=\"wp-image-33152\" srcset=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/confirming-database-name-and-database-username.png 699w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/confirming-database-name-and-database-username-300x122.png 300w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/confirming-database-name-and-database-username-148x60.png 148w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure><\/div>\n\n\n\n<p>Below, in the \u201cCurrent Users\u201d section, you will also see the users and links to change the password.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"241\" src=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/confirming-passwords-of-database-users.png\" alt=\"confirming passwords of database users\" class=\"wp-image-33153\" srcset=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/confirming-passwords-of-database-users.png 700w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/confirming-passwords-of-database-users-300x103.png 300w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/confirming-passwords-of-database-users-174x60.png 174w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/figure><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>After confirming the database name, database username, and password from the hosting account, you can change the information on your wp-config.php file accordingly.<\/li><\/ul>\n\n\n\n<p>Check if it solved the error. If not, let\u2019s move on to the next fix.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Fix_2_Confirm_Your_Database_Host_Information\"><\/span>Fix 2: Confirm Your Database Host Information<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Sometimes, you may see the database connection error even if you enter the correct database name, database username, and password. In such a case, make sure you are using the right information of your database host.&nbsp;<\/p>\n\n\n\n<p>Most of the hosting companies use the local host as the database host. However, the <a href=\"https:\/\/rarathemes.com\/blog\/best-wordpress-hosting\/\">managed WordPress hosting providers<\/a> designate separate servers to host your database. In such a case, the local host is not your database host information.&nbsp;<\/p>\n\n\n\n<p>We recommend contacting your hosting company to confirm the database hosting information.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Fix_3_Repairing_Your_WordPress_Database\"><\/span>Fix 3: Repairing Your WordPress Database&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If you see a different error that reads, \u201cOne or more database tables are unavailable. The database may need to be repaired,\u201d it means your database is corrupted. In such a case, you need to repair the database.&nbsp;<\/p>\n\n\n\n<p>To repair the database, add the following line before \u2018That\u2019s all, stop editing! Happy blogging\u2019 on your wp-config.php file.<\/p>\n\n\n\n<p>define(&#8216;WP_ALLOW_REPAIR&#8217;, true);<\/p>\n\n\n\n<p>After adding the line, visit the page \u201c<strong>http:\/\/www.yoursite.com\/wp-admin\/maint\/repair.php<\/strong>.\u201d This page is accessible even without logging in. You will get the option to repair the database and also optimize it.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"354\" src=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/repairing-database-in-WordPress.png\" alt=\"repairing database in WordPress\" class=\"wp-image-33158\" srcset=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/repairing-database-in-WordPress.png 699w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/repairing-database-in-WordPress-300x152.png 300w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/repairing-database-in-WordPress-118x60.png 118w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure><\/div>\n\n\n\n<p>We recommend selecting the \u201cRepair Database\u201d option since it is quicker.&nbsp;<\/p>\n\n\n\n<p><strong>Note:<\/strong> After repairing your database, make sure to remove the line you added earlier on your wp-config.php file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Fix_4_Fixing_the_Corrupt_WordPress_Database_Files\"><\/span>Fix 4: Fixing the Corrupt WordPress Database Files&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Another reason for the database connection error can be corrupted WordPress files. Whether the corrupt files occurred due to the hacker\u2019s activity or during the file transfer via FTP, you can quickly fix it with the following procedure:&nbsp;<\/p>\n\n\n\n<p><strong>Note:<\/strong> Before proceeding with this fix, make sure to <a href=\"https:\/\/rarathemes.com\/blog\/backup-wordpress-website\/\">backup your WordPress file<\/a> if anything goes wrong later.<\/p>\n\n\n\n<p>You are going to replace the core WordPress version on your website. So you\u2019re not touching any themes, plugins, or media, only the WordPress installation.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Download WordPress from WordPress.org<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/Downloading-WordPress.png\" alt=\"Downloading WordPress\" class=\"wp-image-33155\" width=\"700\" height=\"280\" srcset=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/Downloading-WordPress.png 700w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/Downloading-WordPress-300x120.png 300w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/Downloading-WordPress-150x60.png 150w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/figure><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>Unzip the files on your computer.&nbsp;<\/li><li>Now, delete the wp-content folder and wp-config-sample.php file.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"648\" height=\"400\" src=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/deleting-the-wp-content-and-wp-config-sample-files.png\" alt=\"deleting the wp-content and wp-config-sample files in WordPress\" class=\"wp-image-33211\" srcset=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/deleting-the-wp-content-and-wp-config-sample-files.png 648w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/deleting-the-wp-content-and-wp-config-sample-files-300x185.png 300w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/deleting-the-wp-content-and-wp-config-sample-files-97x60.png 97w\" sizes=\"auto, (max-width: 648px) 100vw, 648px\" \/><\/figure><\/div>\n\n\n\n<p>Now, upload all the remaining files using SFTP to your website. This will overwrite and replace all the corrupted files with fresh ones. We recommend <strong>clearing your browser cache<\/strong> after uploading the files. Check if the database connection error persists.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Fix_5_Check_if_the_Database_Server_is_Down\"><\/span>Fix 5: Check if the Database Server is Down<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If you still see the database connection error even though everything seems fine, it may be that your database server is down. It happens due to traffic overload on the server, and it cannot handle it. Such an issue occurs mostly on shared hosting plans.<\/p>\n\n\n\n<p>If so, contact your hosting provider via phone or live chat. You can ask them if your MySQL server is down or not. If you have your other websites on the same server, you can also check if they are running or not to confirm the database server error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Other_Possible_Fix_for_the_%E2%80%9CError_Establishing_a_Database_Connection%E2%80%9D\"><\/span>Other Possible Fix for the \u201cError Establishing a Database Connection\u201d&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you are facing the error even after applying all the above tips, then here are some additional shots you can take:&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Updating_the_WordPress_Site_URL\"><\/span>1. Updating the WordPress Site URL<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You can try to solve the error by updating your site\u2019s URL using phpMyAdmin.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Access the phpMyAdmin on your hosting account\u2019s dashboard.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"704\" height=\"363\" src=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-phpMyAdmin.png\" alt=\"accessing phpMyAdmin\" class=\"wp-image-33214\" srcset=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-phpMyAdmin.png 704w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-phpMyAdmin-300x155.png 300w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-phpMyAdmin-116x60.png 116w\" sizes=\"auto, (max-width: 704px) 100vw, 704px\" \/><\/figure><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>Click on the SQL menu tab at the top.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"579\" height=\"348\" src=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-the-SQL-tab.png\" alt=\"accessing the SQL tab\" class=\"wp-image-33220\" srcset=\"https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-the-SQL-tab.png 579w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-the-SQL-tab-300x180.png 300w, https:\/\/rarathemes.com\/blog\/wp-content\/uploads\/2021\/08\/accessing-the-SQL-tab-100x60.png 100w\" sizes=\"auto, (max-width: 579px) 100vw, 579px\" \/><\/figure><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>Enter the following query:&nbsp;<\/li><\/ul>\n\n\n\n<p><strong>UPDATE wp_options SET option_value=&#8217;SITE_URL&#8217; WHERE option_name=&#8217;siteurl&#8217;<\/strong><\/p>\n\n\n\n<p><strong>Note<\/strong>: Replace the \u201cSite_URL\u201d part in the query with your actual WordPress site\u2019s URL name.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Reboot_the_Web_Server\"><\/span>2. Reboot the Web Server&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If you have your site on a local server, dedicated server, or VPS (Virtual Private Server), you can try to reboot your server. Doing so will restart your database server, which may fix the temporary glitches.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Reach_Out_for_Technical_Support\"><\/span>3. Reach Out for Technical Support&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If you still see the error, it is time to reach out to the support team of your hosting company. Good <a href=\"https:\/\/rarathemes.com\/blog\/best-wordpress-hosting\/\">hosting companies<\/a> offer 24\/7 support with various options of reaching out, such as phone, email, and even live chat. They will help you out with solving the error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The database connection error can cause a severe dip in your SEO, conversion, as well as visitor\u2019s trust if you soon don\u2019t fix it. Here we have listed eight ways to fix the \u201cerror establishing database connection\u201d in WordPress.&nbsp;<\/p>\n\n\n\n<p>Remember, the most common cause for this error is invalid credentials in your wp-config PHP file. We recommend you to start there. You can try other fixes sequentially if the first one does not work.&nbsp;<\/p>\n\n\n\n<p>You may also want to check out the article on <a href=\"https:\/\/rarathemes.com\/blog\/fix-http-503-error-wordpress\/\">what is 503 error and how to fix it.&nbsp;<\/a><\/p>\n\n\n\n<p>So, how did you fix the \u201cerror establishing a database connection\u201d in WordPress? Do comment below:&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes your website loses connection with your WordPress database. As a result, you see a blank white screen with the message \u201cError establishing a database connection.\u201d&nbsp; There may be many &hellip; <\/p>\n","protected":false},"author":15,"featured_media":33188,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_be_single_description":"","_be_image_uploader":0,"_be_meta_button_label":"","_be_meta_button_url":"","_be_meta_button_newtab":false,"_be_meta_rel_attribute":"","footnotes":""},"categories":[3],"tags":[],"class_list":["post-33147","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","latest_post"],"_links":{"self":[{"href":"https:\/\/rarathemes.com\/blog\/wp-json\/wp\/v2\/posts\/33147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rarathemes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rarathemes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rarathemes.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/rarathemes.com\/blog\/wp-json\/wp\/v2\/comments?post=33147"}],"version-history":[{"count":0,"href":"https:\/\/rarathemes.com\/blog\/wp-json\/wp\/v2\/posts\/33147\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rarathemes.com\/blog\/wp-json\/wp\/v2\/media\/33188"}],"wp:attachment":[{"href":"https:\/\/rarathemes.com\/blog\/wp-json\/wp\/v2\/media?parent=33147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rarathemes.com\/blog\/wp-json\/wp\/v2\/categories?post=33147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rarathemes.com\/blog\/wp-json\/wp\/v2\/tags?post=33147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}