Error establishing a database connection
Fix the database connection error on WordPress: check the credentials in the Database tab, check the database service, check the tables, and roll back a change that broke the connection.
"Error establishing a database connection" means WordPress started but could not log in to its database. The site's files are fine. The usual causes are wrong database settings in wp-config.php, a database that is busy or damaged, or a change that moved the database to a new address. Work through the steps in order.
What you see
- The page "Error establishing a database connection" on the homepage, and often on wp-admin too.
- The error appeared after a deploy, a restore, a clone, or a change to environment variables.
- Only the public pages fail, or only wp-admin fails, while the other works.
Check these first
- Read the error log. Open Logs, pick
error.log, and look at the time of the error. The line usually names the host, the user, or the database, such as "Access denied for user" or "Can't connect to MySQL server". That line tells you which of the causes below to check. - Check the credentials. Open the site's Database tab and reveal the credentials. Compare them with the values in
wp-config.php. A mismatch usually comes from a manual edit or a restore from another site. Reveal needs a recent sign-in. - Check the database. On the Database tab, run Check and repair. It scans the tables and repairs what it finds, and runs as a job. Watch the job on Jobs.
- Check the recent changes. Open Code and User activity. A deploy, a clone of content, or an environment variable change in the last hour is the most likely cause.
Fix it
- If the credentials in
wp-config.phpdo not match the Database tab, put back the values from the Database tab. Change them over SFTP, then restart PHP from Tools. - If the database is damaged, run Check and repair, then reload the site. A repair that fails leaves the error in the log. Open a support request with the job ID.
- If a deploy or a clone broke the connection, open Code and roll back to the release before the change. Rollback changes code only, so a clone may need to be run again.
- If an environment variable changed the database host, set it back under Environment variables, then restart PHP.
Not yet
- A restore from a backup that was taken before a credential rotation does not update the credentials in the restored
wp-config.phpyet. Check the credentials after any restore.
Related
Still stuck?
Email [email protected] with your site name and what you tried, or send us a message.