More fixes

"Error establishing a database connection"

Every WordPress page is built from a database: your pages, posts, orders and settings all live there. This message means WordPress could not log in to that database, so it has nothing to show. Your content is almost always still there. The cause is usually one of three things: the login details changed, the database server is down or overloaded, or some tables are damaged. Below is a rebuilt example (not a real client), then how to tell which cause you have and the safe order of steps.

What visitors see

yourbusiness.com

What the checks found


  

First: which of the three is it?

The safe order of steps

  1. Back up the files through the host's file manager or SFTP before changing anything. Most hosts also keep their own daily database backups; note the newest one, but do not restore it yet.
  2. Compare the four login lines. Open wp-config.php and read DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Compare them with the database and user listed in the host's control panel. A move to a new host very often leaves an old DB_HOST or database name behind; some hosts use a server name rather than localhost.
  3. Reset the database user's password in the control panel if you are unsure of it, and paste the new one into DB_PASSWORD. Check that the user is still attached to the database with all privileges; a move can drop that link.
  4. Repair only if WordPress asks for it. Add define('WP_ALLOW_REPAIR', true); to wp-config.php, open /wp-admin/maint/repair.php, run Repair Database, then remove that line again: the repair page works without a login while it is on.
  5. If the server is overloaded (the error comes and goes, often at busy times), ask the host for the database error log and the account's resource limits. A traffic spike, a bot hammering the site or a runaway plugin query is the usual reason; caching or a bigger plan fixes it, a reinstall does not.
  6. Then test the parts that write to the database: a contact form, a booking or a test order, and log in to the dashboard once.

Common causes and what each one needs

What you seeWhat it meansUsual fix
Error started right after a move to a new hostwp-config.php still names the old database, user or serverCopy the new host's database name, user, password and server into the four lines
Error started after a hosting password or security resetThe database user's password changed and WordPress still uses the old oneReset the database user's password and update DB_PASSWORD
/wp-admin says tables are unavailable or need repairThe login works; one or more tables are damaged, often after a crash or a full diskWP_ALLOW_REPAIR, run the repair, remove the line
Error comes and goes; other sites on the account also failThe database server is down or hitting its limitsHost's status page and support; then caching, bot blocking or a bigger plan
Control panel warns the disk is full or the account is suspendedThe database cannot write, or the host stopped itClear old backups and logs, or settle the account with the host

What not to do

If you can open your host's control panel and a file manager, the steps above are usually enough. If the site earns you money every hour it is down, that is what the box below is for.