What is error establishing database connection in wordpress?
The “Error Establishing a Database Connection” in WordPress means that your website is unable to connect to the MySQL database, which stores all your content, settings, and user data.
Step-by-Step Fix
1. Check wp-config.php for Database Credentials
Go to your WordPress root folder via FTP or File Manager and open wp-config.php. Verify these values:
define('DB_PASSWORD', 'your_database_password'); define('DB_HOST', 'localhost'); // or another value from your host
Incorrect details = connection failure. Get the correct values from your hosting control panel or host support.
2. Check Database Server (DB Host)
Most hosts use localhost, but some (like GoDaddy, Bluehost) may use something else.
Confirm with your host if you’re unsure.
3. Test Database Connection
Create a simple PHP file to test:
if ($mysqli->connect_error) {
die('Connection error: ' . $mysqli->connect_error);
}
echo 'Connected successfully!';
Upload and visit the file to test.
4. Repair the Database
If the credentials are correct but the error persists:
Add this to wp-config.php:
Visit: https://yourdomain.com/wp-admin/maint/repair.php
Run the repair, then remove the line from wp-config.php
5. Check Hosting Server
Your MySQL server might be down.
Contact your hosting support or check the server status from your hosting dashboard.
6. Restore from Backup (if needed)
If the database is corrupted beyond repair and you have a backup, restore it via your host or a backup plugin.
7. Contact Hosting Support
If all else fails, your host can confirm if it’s a server issue or help you reset credentials.