Quantcast
Channel: Beginners Guide To CMS Fixes
Viewing all articles
Browse latest Browse all 10

How to fix the error establishing a database connection in WordPress

$
0
0

Error in database connection 1

When it comes to working with websites, you need to have your website up and running in order to get traffic. When you see an “error establishing a database connection,” it means no one can see your website. This error code lets you know that, for some reason, the PHP code cannot communicate with the MySQL database. If the two languages cannot communicate, you will have a site that does not load.

Causes of the Error

Error in database connection 2Unfortunately, the “error establishing a database connection” message may not be easy to diagnose. There are a few common causes for the error to pop up. You may have the wrong login credentials, which is a common problem if you have just changed the credentials for your database. However, it is also possible that your database has become corrupt or the server may be down. Database corruption is commonly caused by a bad plugin, while servers going down are usually on the web host’s end.

Troubleshooting the Error

Error in database connection 3

Unless the problem is determined to be on the web host’s end, there are a few ways you can troubleshoot to fix the error. The first thing you will need to do is to attempt to determine where the error is occurring. Log out of the admin side of your site and see if you can access your site as a regular visitor. When you visit the site as a visitor, you might receive a different error. If this is the case, then you are likely dealing with a database that has become corrupted. You will need to log into your cPanel and open your wp-config.php file. Finally, add “define (‘WP_ALLOW_REPAIR’, true);” without the quotation marks to the bottom of the code. You will now have the ability to repair your database by visiting www.insertyoururl.com/wp-admin/maint/repair.php. Once you are finished repairing your database, make sure you go back to your wp-config.php file and remove that line of code.

While you have your wp-config.php file open, make sure you check the database settings. You need to make sure that your login credentials have not changed. You will see the credentials at the top of the wp-config.php file that tells you the name of your database, your MySQL database username, your MySQL database password, and the MySQL hostname. Everything needs to match up for the PHP to be able to communicate with the MySQL database. The best way to test your credentials is to create a .php file and see if it can connect to your database. If it does not, you can create a new username and password, and then just edit your wp-config.php file to match.

When to Contact the Host

If you have tried the above measures and are still unable to access your database, it is possible that the web host’s server is down. Contact the company that is hosting your site and let them know what problems you are having. They will help try to recreate the problem, allowing them to find a fix. They may also be able to tell what is causing the error and help you fix it on your end.


Viewing all articles
Browse latest Browse all 10

Trending Articles