Skip to content

Error establishing a database connection

Fix the WordPress database connection error by reading the logs, resetting the database password, checking the tables, and rolling back a change that broke it.

"Error establishing a database connection" means WordPress started but could not log in to its database. Your files are fine. The cause is a wrong or changed database password, a damaged or overloaded database, or a change that broke the site just before.

How do I find the cause?

  1. Read the PHP error log. Open Logs, pick php-error.log, and look at the time of the error. A line such as "Access denied for user" points at the credentials. "Can't connect to MySQL server" points at the database service.
  2. Check the recent changes. Open Deploys on Info, and User Activity. A promote, a restore, a clone, or a password change in the last hour is the most likely cause.
  3. Check the tables. On the Database tab, choose Database access, then Open phpMyAdmin. Select the tables and choose Check table. Or call POST /v1/environments/{id}/database/check with mode set to check.

How do I fix it?

  • Access denied. WP Waterfall writes wp-config.php and you cannot edit it on live. Choose Database access, then the circular arrow, to generate a new password. The job sets the password and rewrites wp-config.php together. Then restart PHP from Tools. See Database access.
  • A table is damaged. In phpMyAdmin, select it and choose Repair table, or call the check endpoint with mode set to repair. Reload the site. If the repair fails, message Nami from the chat button with the table name.
  • A promote broke it. Roll back on live's Info page, under Deploys. Rollback changes code only, so restore the restore point from Backups if the promote also copied content.
  • A restore broke it. Restore a snapshot taken before the change. See Backups.
  • The database is busy or down. Restart PHP from Tools. If the error stays, message Nami from the chat button with the site, the environment, and the log line.

Still stuck?

Email support at wpwaterfall dot com with your site name and what you tried, or send us a message.