Most WordPress database errors come from four causes: wrong connection details in wp-config.php, a database server that is down or overloaded, damaged tables, or a plugin or update that expected a table or column that is not there. The message on screen tells you which one you are dealing with, so the first step is to read it carefully rather than reaching for a repair tool.
The most common one, "Error establishing a database connection", means WordPress could not log in to the database at all. Messages that mention a specific table, such as "Table doesn't exist" or "is marked as crashed", mean the connection works but something inside the database is wrong.
This guide walks through each case in the order I check them when a client sends me a site that is down. Before you change anything, take a backup of the files and the database if you can still reach them.
Read the exact error first
Here are the messages I see most often and what each one usually means.
| Error message | Usual cause | Where to start |
|---|---|---|
| Error establishing a database connection | Wrong credentials, database server down, or server overloaded | wp-config.php, then hosting status |
| One or more database tables are unavailable | Damaged or missing tables | WordPress repair tool or WP-CLI |
| Table 'wp_xxx' is marked as crashed and should be repaired | Damaged MyISAM table | Repair the named table |
| Table 'wp_xxx' doesn't exist | Wrong table prefix, failed migration, or plugin not installed properly | Check prefix and the plugin |
| Unknown column in field list | Plugin or core update did not finish its database upgrade | Run the database update |
| MySQL server has gone away | Query too large or timed out | Server limits, plugin doing heavy queries |
If you see a database error in the admin but the front end is fine, it is usually a plugin problem. If the whole site shows the connection error, it is usually credentials or the server.
Error establishing a database connection
This is the most common database error and usually the quickest to fix. Work through these in order.
1. Check the credentials in wp-config.php
Open wp-config.php in the site's root folder and find these four lines:
define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_user' );
define( 'DB_PASSWORD', 'database_password' );
define( 'DB_HOST', 'localhost' );Compare them with what your hosting control panel shows. Common problems:
- The site was migrated and the new host uses a different database name or user prefix.
- Someone changed the database user's password in the control panel.
DB_HOSTis wrong. Many hosts uselocalhost, but some use a separate hostname or a port number.- The database user exists but is not assigned to the database, or lacks permissions.
If you are not sure the password is right, reset the database user's password in the control panel and update wp-config.php to match.
2. Check that the database server is running
If the credentials are correct, the database server may be down. On shared hosting, check the host's status page or contact support. On a VPS, check the MySQL or MariaDB service status. If other sites on the same server are also down, it is a server issue.
3. Check for overload and full disks
A database server can refuse connections when it hits its connection limit, usually during traffic spikes, bot attacks or when a plugin runs heavy queries. A full disk also stops the database from working, because it cannot write temporary files or logs. Both show up as the same connection error, so check the disk usage and the server's error log.
If the error comes and goes, overload is the likely cause. Caching, blocking bad bots and finding the heavy plugin usually solve it.
Damaged or crashed tables
If the error mentions unavailable or crashed tables, the connection is fine but some tables are damaged. This can happen after a server crash, a full disk, or a sudden restart during a write.
Option A: the built-in WordPress repair tool
Add this line to wp-config.php, just above the line that says "That's all, stop editing":
define( 'WP_ALLOW_REPAIR', true );Then visit yoursite.com/wp-admin/maint/repair.php. You can choose "Repair Database" or "Repair and Optimize Database". The page does not require a login, which is exactly why you must remove the line again as soon as you are done.
Option B: WP-CLI
If you have SSH access, WP-CLI is faster and does not expose a public page:
wp db check
wp db repairwp db check reports any problems. wp db repair attempts to fix them.
A note on table engines
Repair commands work on MyISAM tables. Most modern WordPress databases use InnoDB, which handles crashes differently and does not support the classic repair command. If an InnoDB table is genuinely corrupted, the reliable fix is usually restoring that table or the whole database from a backup, or asking your host to run InnoDB recovery. This is one of many reasons good backups matter.
Missing tables and unknown columns
"Table doesn't exist" usually has one of three causes.
Wrong table prefix. In wp-config.php, the $table_prefix value must match the prefix of the tables in the database. After a migration, I often find the config says wp_ while the tables start with something like wpab_. Open phpMyAdmin, check the real prefix, and update the config.
A plugin that did not finish installing. Some plugins create their own tables on activation. If activation failed, the plugin later looks for a table that is not there. Deactivating and reactivating the plugin often recreates it.
A failed migration or import. If the database was imported from a file that was cut short, some tables may be missing completely. Compare the table list with the original, or re-import from a complete backup.
"Unknown column" errors after an update usually mean the database upgrade step did not run. Visit /wp-admin/upgrade.php, or run wp core update-db. For WooCommerce, check the WooCommerce status page for a pending database update.
When the error is a sign of something worse
Sometimes a database error is a symptom rather than the problem.
- Hacked sites often have injected content, unknown admin users or changed options in the database. If you also see spam pages, odd redirects or users you did not create, read how to clean a hacked WordPress site before repairing anything.
- Repeated overloads may come from a plugin running inefficient queries on every page load. Query Monitor on a staging copy shows which plugin is responsible.
- A "critical error" message sometimes hides a database problem underneath. Turning on debug logging, as explained in fixing the WordPress critical error, shows the real message in the log.
How to prevent database problems
A few habits stop most of these errors from happening again:
- Automatic daily backups, stored off the server, with at least one restore test.
- Monitor disk space so the server never fills up.
- Keep WordPress, plugins and PHP up to date, and run database updates when prompted.
- Remove plugins you no longer use, and the tables they leave behind.
- Use a staging site for big updates and migrations.
These all appear in my WordPress maintenance checklist.
The short version
Read the exact message first. A connection error means credentials, the server, or overload. Crashed or unavailable tables mean damage, which you repair with WP_ALLOW_REPAIR or wp db repair, or by restoring from backup if the tables use InnoDB. Missing tables and unknown columns usually come from a wrong prefix, a half-installed plugin or an unfinished update.
If your site is down with a database error and you want it fixed quickly and safely, that is exactly what my website bug fixing service is for. Send me the error message and the site address.