Fixing a Corrupted MySQL Table (REPAIR TABLE)

Updated 2026-10-28

A corrupted table takes a database from "serving traffic" to "throwing errors on every query" in an instant — usually after an unclean shutdown, a full disk, or dying hardware. The repair path depends entirely on the storage engine, so step one is knowing which you've got.

1. Confirm the corruption

The error log is explicit about it: grep -i -E 'corrupt|crashed' /var/log/mysql/error.log. From a client, CHECK TABLE users; reports a table's health and SHOW TABLE STATUS; shows each table's engine.

2. MyISAM — REPAIR TABLE

REPAIR TABLE works on MyISAM (and ARCHIVE/CSV), not InnoDB:

REPAIR TABLE users;
-- Msg_type: status   Msg_text: OK   <- fixed
-- offline / mysqld down? use myisamchk instead:
--   myisamchk --recover /var/lib/mysql/db/users.MYI

An OK in the result means the index/data were rebuilt. Take a file-level copy of the table first if the data matters — a repair can discard unrecoverable rows.

3. InnoDB — don't REPAIR, recover

REPAIR TABLE can't fix InnoDB. If InnoDB corruption keeps the server from even starting, set innodb_force_recovery in my.cnf (start at 1, increase only as needed), start MySQL read-mostly, then mysqldump the data out, drop the table, and reload it. Set innodb_force_recovery=0 again afterwards — leaving it on is itself a risk.

4. Fix the cause

Corruption is a symptom. The usual root causes are a disk that filled up (see no space left on device), an unclean power loss, or failing storage — address that or you'll be repairing again next week.

Practise a database recovery

DB corruption — including an interactive REPAIR TABLE puzzle — is one of the simulator's incidents. Work it hands-on in a full incident response shift.

Learn it by doing

Create a free account and practise on a live fleet.

← All guides