How to repair database tables

A table can get damaged if a write was interrupted, for example a script crashed in the middle of saving. Signs of damage: "Table is marked as crashed" or "Incorrect key file", some pages do not open, errors on save.

Export the database before repairing: export. If the repair goes wrong, you will have something to return to.

With phpMyAdmin

  1. Open phpMyAdmin: "Databases" → three dots on the database → "Database web-interface".
  2. Choose the database on the left.
  3. Tick all tables: "Check all".
  4. In the "With selected" list choose "Check table".
  5. If there are errors, tick the tables again and choose "Repair table".
Tables ticked, the "With selected" list
Tables ticked, the "With selected" list
Table check result
Table check result

In the check result a healthy table shows OK. If a table has error messages, repair it. The same list has "Optimize table" — it compacts a table after a lot of data was deleted.

Checking from the panel

The "Databases" list has a "mysqlcheck status" column. The panel can check and repair tables itself with the mysqlcheck utility: tick the database and find the mysqlcheck action on the top toolbar (some buttons are hidden under "More"). If one table cannot be repaired, run the repair for the whole database.

MyISAM and InnoDB

The table type is shown in phpMyAdmin in the "Type" column of the table list.

Repair works for MyISAM tables. InnoDB tables recover on MySQL start, the repair command is not supported for them. If the error stays, restore the database from a backup: Backup copies.

If it did not help

  • "Table doesn't exist" — the table is missing, not damaged. Load it from a dump: database import.
  • Check the site error log: site logs. The cause may not be in the database.
  • Restore the database from a backup made before the failure.
Questions and answers
The site shows "Table is marked as crashed", some pages do not open, data is not saved.
In phpMyAdmin: tick the tables and choose "Check table" in "With selected".
Restore the database from a backup.