Console9

MySQL: Table is marked as crashed and should be repaired

Diagnose and fix MyISAM table corruption in MySQL with REPAIR TABLE and mysqlcheck.

MySQL produces "Table 'db.table' is marked as crashed and should be repaired" when a MyISAM table's index or data file is corrupted.

What Causes This Error

MyISAM table corruption occurs after unexpected server shutdowns, disk failures, or the MySQL process being killed ( kill -9). MyISAM does not have crash recovery like InnoDB — writes that were in progress during the crash leave the table in an inconsistent state.

How to Fix

  1. Repair the specific table:
REPAIR TABLE myapp.broken_table;
  1. If REPAIR fails, try with the extended option:
REPAIR TABLE myapp.broken_table EXTENDED;
  1. Repair from the command line with mysqlcheck:
mysqlcheck -u root -p --repair myapp broken_table
  1. For severe corruption, use myisamchk directly on the table files (stop MySQL first):
sudo systemctl stop mysql
myisamchk -r /var/lib/mysql/myapp/broken_table
sudo systemctl start mysql

Prevention

Migrate MyISAM tables to InnoDB to gain crash recovery and transactional consistency:

ALTER TABLE myapp.broken_table ENGINE=InnoDB;

InnoDB uses a write-ahead log (WAL) that survives unexpected shutdowns.