If your site ever stops working and you see this message ‘error establishing a database connection’ you might want to scan this checklist.
wp-config.php
Most of the time this error message is caused by a problem in the wp-config file.
This is where the database details are which connect your WordPress files to your database in phpMyAdmin.
You can find this file in your public_html root directory on your server.
If you’ve ever edited this file or installed WordPress manually, you’d be familiar with this file.
The settings in your wp-config.php shouldn’t have changed however you might want to check them.
You can also repair your database while you have your wp-config.php open simply by adding this code to the file.
define(‘WP_ALLOW_REPAIR’, true);
Make sure you remove this line of code after you have fixed your database connection error message.
Once you’ve added this code to your wp-config.php file, go to:
yourdomain.com/wp-admin/maint/repair.php
You’ll then get a screen which looks something like this:
If your database still has errors, send the errors to your web host or the WordPress forums.
cPanel Databases
You can go into cPanel and find your database name, username and password using the details from your config file.
define('DB_NAME', 'name');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
Make sure these details match or you will get the database connection error message.
Finding Your Database Details in Cpanel
- Login to your web hosts cPanel
- Scroll down to the database section
- Click on MySQL Databases
- Scroll down to the current databases section and view your database name and username
You can also repair your database here simply by selecting it from the menu.
500 Internal Server Error
Sometimes you may get an 500 Internal Server Error when you have a problem with your database connection. It doesn’t always display as a database connection errors message.
I tested this on a local installation of WordPress by changing the password in the wp-config file and got this message.
Conclusion
Still getting errors?
You’ll find most good hosting providers will be able to fix database errors very easily.
Was This Tutorial Helpful?