Troubleshoot the WordPress Error: One or more database tables are unavailable. The database may need to be repaired.

Oh No! The Database is Borked!

Recently while completing some WordPress maintenance work, I accessed the WordPress login screen on a site and was met with the WordPress error: “One or more database tables are unavailable. The database may need to be repaired.” Other public pages of the site loaded normally.

Here are two recommended approaches to resolving this issue.

Please Note

Before taking any action, make sure you create a backup of your database. You might also take the opportunity to find your last good database backup.

Allow WordPress Database Repair by Adding a Line to wp-config.php

Download your wp-config.php file and added the following line:

define('WP_ALLOW_REPAIR', true);

Typically, define() would be added just before the end of the editable area of wp-config.php, for example:

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the Codex.
 *
 * @link https://codex.wordpress.org/Debugging_in_WordPress
 */
define( 'WP_DEBUG', false );
define('WP_ALLOW_REPAIR', true);
/* That's all, stop editing! Happy publishing. */ 

Once your wp-config.php file is updated, place it back on the server replacing the previous version.

Afterwards, visit to https://yourdomain.com/wp-admin/maint/repair.php in your browser (replacing yourdomain.com with your site’s domain, of course). Read the instructions there for repairing your site’s database.

You should be presented with options to “Repair Database” and “Repair and Optimize Database.”

Attempt the first option, “Repair Database.”

WordPress should return information on table health. For example:

The wp_users table is okay.
The wp_usermeta table is okay.
The wp_posts table is okay.
The wp_comments table is okay.
The wp_links table is okay.
The wp_options table is not okay. It is reporting the following error:
Table is marked as crashed. WordPress will attempt to repair this table…
Failed to repair the wp_options table.
Error: Number of rows changed from XXX to YYY
The wp_postmeta table is okay.
The wp_terms table is okay.
The wp_term_taxonomy table is okay.
The wp_term_relationships table is okay.
The wp_termmeta table is okay.
The wp_commentmeta table is okay.
Some database problems could not be repaired.
Please copy-and-paste the following list of errors
to the WordPress support forums to get additional assistance.

In my experience this approach may not solve the issue, but it may identify the table or tables experiencing issues.

If the issue persists, make sure to revert your changes to your wp-config.php file and restore the file on the server to its original settings before proceeding to the next troubleshooting option. Otherwise, this WordPress database repair page will be publically exposed if you are working on the production server.

Repair Database Table with PHPMySQL

Locate phpMyAdmin in your hosting account’s control panel.

Find the database used by your website. The database’s name can be found in your wp-config.php file. For example:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'accountname_databasename' );

Where accountname_databasename will be your hosting account username and the name of the database.

In phpMyAdmin select all the tables. Then, select “Repair table” from the dropdown.

In phpMyAdmin select all the tables.  Then, select "Repair table" from the dropdown.

The process will run through the selected tables and typically return either:

Status: OK

or

Note: The storage engine for the table doesn’t support repair

Afterwards, test the original page where you witnessed the database error.

Restore Database from Last Good Backup

If the above does not effect a repair, you will likely need to restore your last good database backup. I’m not going into that process in this post, but you should be able to find adequate documentation of the process online. Many possible paths exist. A database restoration might involve a backup provided by your hosting provider using tools provided by them, perhaps using phpMyAdmin to import a previous .sql export, or using the backup plugin you use for scheduled backups.

Have Feedback? Leave Me a Comment Below

If you have thoughts, or a different troubleshooting process for resolving this issue, please feel free to leave me a comment. Comments are always appreciated.

Have a good day. Happy troubleshooting!

Vance Bell

Vance Bell

Hi there, glad you made it! I’m Vance Bell, a freelance web designer/developer and often marketing consultant.

Monday to Saturday I help businesses and organizations grow attention and revenue. Sometimes on Sunday I take a break and binge watch Netflix.

Owner of Pixel Engine, a Philadelphia-based web design and online marketing studio.

If you’d like to hire me, I’d love to hear from you. If you just have a question, feel free to ask.

Related Posts

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top