How To Fix The Error Establishing A Database Connection In WordPress
Last modified: February 4, 2020
The panic will always set in when you see the error that says ‘Error Establishing a Database Connection’. This is a fatal error that basically means no-one can access your website due to a connection issue between your website and the database.
This error can be caused by a number of different things, so it is really hard to identify and solve. However, here is a quick guide to possible solutions.
Step One: Check WordPress Database Credentials
One of the most common reasons why the database connection error happens is because there are incorrect database credentials. If you’ve recently moved hosts, this is probably the reason.
So, use an FTP client like Filezilla and then open up the wp-config.php file.
Look for the following lines of code:
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define( 'DB_NAME', 'database_name_here' ); /** MySQL database username */ define( 'DB_USER', 'username_here' ); /** MySQL database password */ define( 'DB_PASSWORD', 'password_here' ); /** MySQL hostname */ define( 'DB_HOST', 'localhost' );
Check the settings of this with the details stored with your host; especially the database name, username, password and database host. If they’re incorrect, change them, save the file and this should resolve the issue.
If this isn’t the problem with your website, you need to continue on with the steps below.
Step Two: Check Database Host Information
Most hosting companies will use localhost as the database host. However, some do not. If this is the case, then you need to check with your host what the correct value is. Enter in the correct database into the right field on the wp-config.php file.
Afterwards, check your website. If that was the problem, it should now work.
Step Three: Repair Database
Sometimes you might see the error
‘One or more database tables are unavailable. The database may need to be repaired.’
To repair your database, add the following code to your wp-config.php file. Ensure it is done before the final line
Once done, visit the page http://www.yoursite.com/wp-admin/maint/repair.php and repair the database. After you’ve completed repairs, remove the line
from the wp-config.php file so other users can’t corrupt your database.
Step Four: Check Your Database Server Is Active
Another common issue is that the database server is offline. To check this, call up your hosting provider and ask. If it is down, they will solve the problem for you. Or they might have another solution by looking at your website.
Final Word: How To Fix The Error Establishing A Database Connection In WordPress
Don’t let a small issue ruin your WordPress website. Use the fix above to get your website working again. You’ll be glad of knowing how to fix your WordPress website from this easy-to-fix problem.