Skip to content

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

  1. 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.
  2. Check the credentials. Open the site's Database tab, choose Database access, and show the password. Compare the name, username, and password 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.
  3. Check the tables. On the Database tab, choose Database access, then Open phpMyAdmin. Select the tables and choose Check table.
  4. Check the recent changes. Open Deploys on Info, 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.php do not match the Database tab, put back the values from the Database tab. Change them over SFTP, then restart PHP from Tools.
  • If a table is damaged, select it in phpMyAdmin and choose Repair table, then reload the site. If the repair fails, open a support request with the table name.
  • If a deploy or a clone broke the connection, open Deploys on live's Info page 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.php yet. Check the credentials after any restore.

Still stuck?

Email [email protected] with your site name and what you tried, or send us a message.