Blog
SavedSearch
Visit Hostlelo

Check and Repair a WordPress Database With WP-CLI and cPanel

Back up, check, then repair or rebuild your WordPress database with WP-CLI, cPanel or the browser, and learn why REPAIR does nothing for InnoDB tables.

The short answer

A step by step guide to checking and repairing a WordPress database with WP-CLI, cPanel and the built-in repair page. It explains why REPAIR TABLE only works on MyISAM, ARCHIVE and CSV tables, and how to rebuild InnoDB tables instead. It ends with tests that prove the fix worked, troubleshooting for common MySQL errors and a message you can send to your host.

Reading options

On this page

If your WordPress site throws "Error establishing a database connection" or complains about a damaged table, the safe order is simple: take a backup, run a check, and only then repair or optimize. With WP-CLI that is wp db check and wp db repair, and in cPanel it is the Check Database and Repair Database buttons.

Here is the part most guides skip. The MySQL REPAIR TABLE statement only works on MyISAM, ARCHIVE and CSV tables, so on an InnoDB table a "repair" quietly does nothing useful, and you need a different fix.

By the end of this guide you will know how to back up, check, repair and rebuild a WordPress database from SSH, from cPanel and from the browser, and how to tell whether it actually worked.

What a database check and repair actually does

Your WordPress database is a set of tables, which are like spreadsheets that hold posts, users, settings and so on. Each table is stored by a storage engine, the part of MySQL that decides how rows are written to disk. The two you will meet are InnoDB and the older MyISAM.

Think of a library. A check is a librarian walking the shelves and comparing every book with the catalogue cards. A repair is the librarian fixing the cards so they match the shelves again. That second job only works if the library uses the kind of card system the librarian knows how to fix.

That is the InnoDB catch. CHECK TABLE can inspect InnoDB, MyISAM, ARCHIVE and CSV tables. REPAIR TABLE only handles MyISAM, ARCHIVE and CSV. So the check works on almost everything, but the repair command is useless on InnoDB.

For InnoDB, the closest everyday tool is a rebuild. MySQL's OPTIMIZE TABLE on an InnoDB table is mapped to ALTER TABLE ... FORCE, which rebuilds the table to update index statistics and free unused space. An index is the table's lookup list, like the index at the back of a book.

Made-up example: Sara runs a recipe blog. After her server lost power, her wp_options table, which stores site settings, came back marked as crashed. It was a MyISAM table, so wp db repair fixed it in seconds. Her friend Omar had the same symptom on an InnoDB site, ran the same command, saw "Success" and the problem stayed. His fix was a rebuild from a dump, which is covered below.

Before you start

Run through this list first. It takes five minutes and saves hours.

  • SSH or WP-CLI access. WP-CLI is the command line tool for WordPress. You need a shell on the server, and the wp command must work from your site's folder.
  • cPanel access if you prefer clicking buttons, or if WP-CLI is not available on your plan.
  • A full backup of the database, plus your files if you can. Never repair without one.
  • A maintenance window. During mysqlcheck, each table is locked while it is processed, so other sessions cannot use it. Pick a quiet hour.
  • The location of `wp-config.php`. It is usually in the WordPress root folder, next to wp-admin and wp-content. WP-CLI reads your database name, user, password and host from it.
  • Your risk level. A check is read only and safe. A repair or rebuild writes to the table, and MySQL's own docs warn that a repair can, in some cases, cause data loss. That is why the backup comes first.

If you are new to how servers, databases and control panels fit together, read what web hosting is and how the pieces fit first and come back.

Check and repair with WP-CLI

This is the main route and the one I use on every server. Connect over SSH and move into your WordPress folder before running anything.

Step 1: Take a backup first

The wp db export command runs mysqldump with the credentials from wp-config.php and writes your database to a SQL file.

cd /home/exampleuser/public_html
wp db export before-repair.sql

You should see a line that starts with Success: Exported to followed by the file name. Copy that file off the server too, because a backup that lives on the same broken disk is only half a backup.

Step 2: Confirm WP-CLI can see the site

The wp core is-installed command prints nothing at all. It reports through its exit code, so ask the shell for that code straight after.

wp core is-installed
echo $?

You want to see 0. Any other number means WordPress is not installed in this folder, or WP-CLI cannot reach the database, so fix that before going further.

Step 3: Find out which engine your tables use

Do not guess whether your tables are InnoDB or MyISAM. The SHOW TABLE STATUS statement lists every table with an Engine column, and wp db query runs it with the details from wp-config.php.

wp db query 'SHOW TABLE STATUS'

Look down the Engine column. Note any table that says MyISAM, because only those can be repaired with REPAIR TABLE. If you want a shorter list, MySQL lets you filter, for example SHOW TABLE STATUS WHERE Engine = 'MyISAM'.

Step 4: Run the check

The wp db check command runs mysqlcheck --check using DB_HOST, DB_NAME, DB_USER and DB_PASSWORD from wp-config.php.

wp db check

When everything is fine, the last line reads Success: Database checked. Anything else, such as an error or a "corrupt" message, tells you which table to deal with.

Note that this command does not check whether WordPress itself is installed. That is why Step 2 used wp core is-installed.

If the check fails because of login details, you can pass a different database user with --dbuser and --dbpass. By default WP-CLI skips your MySQL option files to avoid trouble from bad settings, and --defaults tells it to load them.

Step 5: Repair MyISAM tables

The wp db repair command calls mysqlcheck with repair turned on, using the same credentials.

wp db repair

A successful run ends with Success: Database repaired. For MyISAM tables that really is a repair. For InnoDB tables nothing gets fixed, because REPAIR TABLE does not support that engine, so do not expect a fix on those tables. Run Step 4 again afterwards to see where you stand.

Step 6: Rebuild InnoDB tables instead

For an InnoDB table, the rebuild is the useful move. The wp db optimize command runs mysqlcheck with optimize turned on, which sends OPTIMIZE TABLE to each table.

wp db optimize

You should see Success: Database optimized. at the end. On InnoDB tables MySQL also shows the note "Table does not support optimize, doing recreate + analyze instead" followed by a status of OK. That note is normal. It means the table was rebuilt.

If you only want to rebuild one table, this command uses the MySQL "null alteration" trick, telling the table to switch to the engine it already uses, which forces a rebuild.

wp db query 'ALTER TABLE wp_options ENGINE = InnoDB'

Change wp_options to the table your check flagged. Your table prefix may differ from wp_, so copy the name exactly as SHOW TABLE STATUS printed it.

A rebuild normally uses online DDL, a way of changing a table while the site keeps reading and writing to it. Tables with a FULLTEXT index, a special index for word searches, make MySQL use the older table copy method instead. On a big table, wait for a quiet hour.

Step 7: If the InnoDB check still fails

Sometimes CHECK TABLE reports real corruption on an InnoDB table. MySQL documents rebuilding a table by dumping it with mysqldump and reloading it with mysql. Your backup from Step 1 is that dump for the whole database.

If the check reports corruption or makes InnoDB fail, MySQL points to the innodb_force_recovery option. That is a server level setting, and on shared hosting you cannot touch it. This is the point to stop and contact your host.

Variants

Not everyone has SSH. Here are the other routes, from most to least control.

cPanel MySQL Databases tool

cPanel has a built-in check and repair tool. Open MySQL Databases in the Databases section of cPanel. In cPanel & WHM version 120 and later this interface is called Manage My Databases, so look for that name if you are on a newer server.

  1. Take a backup first, using your host's backup tool or the WP-CLI export above.
  2. Find the Check Database menu, select your WordPress database and click Check Database.
  3. A new screen opens while the test runs. If it says Check Complete, the database is working. Click Go Back.
  4. If you need a repair, select the same database in the Repair Database menu and click Repair Database.
  5. When Repair Complete appears, the repair succeeded. Click Go Back.

The same InnoDB rule applies here. A "Repair Complete" message on an InnoDB database does not mean a damaged InnoDB table was rebuilt.

cPanel phpMyAdmin

phpMyAdmin is a web tool for browsing tables and running queries. In cPanel it lives at cPanel > Home > Databases > phpMyAdmin. cPanel's docs say to use it for working inside existing databases and running queries, and not to create databases or users with it.

  1. In the left pane, click your WordPress database name.
  2. Tick Check All to select every table, or tick only the table you are worried about.
  3. Open the With selected list and choose Repair table for MyISAM tables, or Optimize table for InnoDB tables.
  4. phpMyAdmin shows a result for each table. You want a status of OK.

You can also run the same SQL statements from this guide, such as SHOW TABLE STATUS or CHECK TABLE wp_options, in phpMyAdmin's query box.

The WordPress repair page in the browser

WordPress ships its own repair script. It is meant for the moment when the database is so broken you cannot log in, which is also why it needs no login. That makes it handy and risky at the same time.

Back up first, then open wp-config.php in your file manager or editor and add this line next to the other define lines.

define( 'WP_ALLOW_REPAIR', true );

Now open https://example.com/wp-admin/maint/repair.php in your browser, using your own domain. Start the repair from that page and let it finish before you close the tab.

The WordPress docs say this setting should only be enabled when needed and disabled once the issue is solved. As soon as you are done, delete the line or change true to false. While the constant is on, anyone who knows the URL can open that page.

How to check it worked

Run these four tests in order. Each one checks a different layer.

The first command confirms WP-CLI can reach a working install.

wp core is-installed && echo "installed"

You should see installed. If nothing prints, the exit code was not zero and something is still wrong.

The second command re-runs the table check.

wp db check

The final line should read exactly Success: Database checked.

The third command reads one real setting out of the wp_options table, which proves WordPress can query its own data.

wp option get home

You should see your site address, for example https://example.com. A blank result or an error points back at the options table.

The last test is the browser. Open your home page and https://example.com/wp-admin/ in a private window. Both should load without the database error, and you should be able to log in. If you used the repair page, also confirm that https://example.com/wp-admin/maint/repair.php no longer offers a repair.

Troubleshooting

"Error establishing a database connection"

This message means WordPress cannot talk to MySQL at all. The WordPress docs say it is usually caused by wrong details in wp-config.php, so check the database name, username, password and host first.

If those are right, the database may have hit its quota or the database server may be down, and both need your host. A table repair will not help until the connection works, because the tools need that same connection.

"Access denied for user 'exampleuser'@'localhost' (using password: YES)"

This is MySQL error 1045. The username or password in wp-config.php does not match what MySQL has stored for that user.

Compare the values with the database user in the MySQL Databases tool in cPanel. If they look right, reset the password for that user there and update wp-config.php to match. WP-CLI uses the same details, so it fails the same way until this is fixed.

Table 'wp_options' is marked as crashed and should be repaired

This is MySQL error 1194, and you will usually meet it on MyISAM tables. Take a backup, then run wp db repair or use Repair table in phpMyAdmin on that table. Run wp db check again afterwards.

If you instead see "is marked as crashed and last (automatic?) repair failed", that is error 1195. Try the repair once more after the backup, and if it still fails, restore that table from your backup or ask the host.

Incorrect key file for table 'wp_posts'; try to repair it

This is MySQL error 1034. It points at a damaged index. On MyISAM run a repair. On InnoDB run wp db optimize or the ALTER TABLE ... ENGINE = InnoDB rebuild from Step 6.

"Success: Database repaired." but the errors continue

This often means the broken table is InnoDB. The repair step ran and simply had nothing it could do. Go back to Step 3, confirm the engine, then rebuild with Step 6 or restore from the dump made in Step 1.

The repair page still opens weeks later

If https://example.com/wp-admin/maint/repair.php still shows repair buttons, WP_ALLOW_REPAIR is still set to true in wp-config.php. Remove the line now. Search the file for every copy, because a second define further down is easy to miss.

The check takes forever or the site freezes

mysqlcheck locks each table while it works on it, and large tables take time. Running it across all databases with --all-databases can take a long time. Run it in a quiet hour, and on a huge site check one table at a time with CHECK TABLE in phpMyAdmin. MySQL also suggests CHECK TABLE QUICK on big InnoDB tables to avoid a semaphore wait timeout, a safety limit on very long internal waits.

Pro tips and security notes

  • Treat WP_ALLOW_REPAIR like a door you prop open for a delivery. Close it the moment you are done, and never commit it to version control or leave it in a staging copy.
  • Always check before you repair. A check is read only, and it tells you which tables need work, so you do not rebuild a 2 GB table for nothing.
  • Keep the before and after backups for a few days. If a plugin acts oddly next week, you have something to compare against.
  • Do not run OPTIMIZE on a schedule as a habit. It rebuilds whole tables, which costs time and disk. Run it when a check flags a problem or after you delete a very large amount of data.
  • If you are moving to a VPS where you run MySQL yourself, these same commands work there, and you will also have access to the error log. The guide to installing DirectAdmin on a VPS covers setting up that kind of server.
  • Heavy scheduled jobs and big imports are a common trigger for table trouble on busy sites. Moving WordPress cron to a real server cron job, as shown in replacing WP-Cron with a real cron job, spreads that load more predictably.

When to ask the host

Ask your host when the database server itself is down or out of quota, when an InnoDB check crashes the server, when you see disk or file system errors, or when a MyISAM repair fails twice. These need server-level access, logs or innodb_force_recovery, which shared hosting accounts do not have.

The one message worth forwarding

If you need help, send this to your host or developer. Fill in the parts in capitals.

Hi, my WordPress site at example.com is showing: PASTE THE EXACT ERROR. I took a full database backup with wp db export at TIME. wp db check reports a problem on table TABLE NAME, and SHOW TABLE STATUS says its engine is ENGINE. wp db repair finished with "Success: Database repaired." but the error is still there. Could you check the MySQL error log for this database, confirm the server has free disk space, and either rebuild that table or restore it from your latest backup? Please do not change anything else. Thank you.

The takeaway: back up, check, confirm the engine, then repair MyISAM or rebuild InnoDB, because a repair on InnoDB only looks like it worked.

At the time of writing (24 November 2026), the latest WordPress releases are 7.1.5, a security release from 18 November 2026, and 7.2 Release Candidate 1 from 17 November 2026, and none of the steps above depend on which one you run.

Reader questions

Is it safe to run wp db check on a live site?

Yes, a check only reads the tables. Each table is briefly locked with a read lock while it is checked, so a very large site may feel slow for a moment.

Will repairing the database delete my posts?

It should not, but MySQL warns that a repair can cause data loss in some cases, such as file system errors. That is why you export a backup before any repair.

How do I know if my tables are InnoDB or MyISAM?

Run SHOW TABLE STATUS through wp db query or phpMyAdmin and read the Engine column. It lists the storage engine for every table.

Do I need to be logged in to use the WordPress repair page?

No. The repair page works without a login because it is built for databases so damaged that logging in fails, which is exactly why you must turn it off afterwards.

How often should I optimize my WordPress database?

Only when a check flags a problem or after you delete a large amount of data. Optimizing rebuilds whole InnoDB tables, so running it on a timer wastes time and disk.

Can my host repair the database for me?

Yes, and the WordPress docs suggest asking your host to run CHECK and REPAIR if you are not comfortable doing it. Hosts also have server level tools and logs that a normal account cannot reach.

Sources & further reading

  1. WP-CLI: wp db check
  2. WP-CLI: wp db repair
  3. WP-CLI: wp db optimize
  4. WordPress: Editing wp-config.php (WP_ALLOW_REPAIR)
  5. WordPress: Common WordPress errors
  6. MySQL 8.4: REPAIR TABLE Statement
  7. MySQL 8.4: mysqlcheck
  8. MySQL 8.4: OPTIMIZE TABLE Statement
  9. MySQL 8.4: Rebuilding or Repairing Tables or Indexes
  10. cPanel Docs: MySQL Databases

Originally published . About our editorial updates.

Your next project deserves a better foundation.

Explore hosting built for your next chapter.

Explore hosting

Find your next answer.

Search published guides and articles.

Ctrl / ⌘ K to open · Esc to close