For WordPress users, the phrase “Error establishing a database connection” can be a nightmare. This message is the sign that your website is not communicating properly. In other words, if you do not resolve it immediately, your website can go down. Therefore, you must take immediate action.
Don’t panic if your website is currently experiencing a similar problem. In this case, stay calm and try to find the source or trigger of the problem. For instance, you can overcome WordPress error establishing a database connection in the following steps bellow.
Check Database Login Credentials
The first step to overcome WordPress error establishing a database connection is to check your database login credentials. Make sure your database login credentials are correct, especially if you have just migrated to the new hosting.
You can check it in the
wp-config.php file which is usually in the root of your WordPress site. After making sure everything is in the right condition, you can check your site. If the condition is still error, you can continue to the next stage.
/** MySQL database username */ define('DB_USER', 'your-database-username'); /** MySQL database password */ define('DB_PASSWORD', 'your-database-password'); /** MySQL hostname, usually just set it as localhost */ define('DB_HOST', 'localhost');
Contact Your Web Host Provider
You can try to contact your web host to try to ask for help to overcome the WordPress error establishing a database connection that you are experiencing.
After that, ask if the database server is currently having problems. Usually, they will try to help you find the cause of the problem you are experiencing, or even help you fix it.
WordPress error establishing a database connection can be caused by numerous reasons. Therefore, this step is important to ascertain whether the problem is with server interruption or other issues. If it turns out it’s not from them, and they can’t help, you can move on to the next step.
Check Your Plugin or Theme Files
Connect your host via FTP. Next, log in using your FTP account password. After the login process is successful, you can connect to the server and navigate to the WordPress root folder.
Then, look for the file “public_html” or “www” and find sub-folders like “wp-content” and “wp-admin”.
Next, you need to enter “wp-content” and rename the “plugins” folder. In this case, you can change the name to anything. After that, you can go back to your site and check if it’s still an error.
If the error still exists, you can do the same thing in the “themes” folder. If these two steps have still not succeeded in resolving your WordPress error establishing a database connection problem, then the cause is something else.
Repair Damaged Database
In some cases, WordPress error establishing a database connection can occur because of damage to your website database.
Therefore, the steps you can take is to check it through the WordPress dashboard
YOURSITE.com/wp-admin/. If you see the words “error establishing a database connection”, you can proceed to the second step.
Backup Your Database First
Before starting the repairing process, you should do a database backup. This step is important because these repair steps will manipulate information in your database. Therefore, you should take steps to anticipate all the worst possibilities.
To backup database, you can use plugins from WordPress, such as UdraftPlus or Duplicator. However, if you want to backup manually, you can use phpMyAdmin on your cPanel. Once completed, you can enter the next stage to fix the WordPress error establishing a database connection.
The second step you need to do is you should connect your site via FTP and download the
Next, edit the file to
define ('WP_ALLOW_REPAIR', true); and upload it again. After that, go to
YOURSITE.com/wp-admin/maint/repair.php and click the “Repair database” button.
Restore the Default Files
You can always restore the default WordPress files by downloading a clean version of WordPress. After that, copy everything you have at the moment. Next, download the latest package, unload it, browse the archive and delete the “wp-content” folder inside.
Next, you need to connect your site via FTP. Then, open the main WordPress root and upload your latest WordPress file. In this process, you can overwrite everything.
After the upload process is complete, you can return to your site and see if your site still has problems.
Those are some ways to fix WordPress error establishing a database connection problem, that you can try.
To find the main problems on your website, you should consult with your host manager. Finally, I hope the steps above can help your website work normally.