How to check and repair MySQL tables

Detect and fix corruption in MySQL/MariaDB MyISAM and InnoDB tables using CHECK TABLE and REPAIR TABLE.

Detect and fix table corruption in MySQL and MariaDB using the CHECK TABLE, REPAIR TABLE, and mysqlcheck commands.

Step-by-Step: Check and Repair MySQL Tables

1. Check a Table for Errors

CHECK TABLE myapp.users;

MySQL reports the table status: OK (no errors), Table is already up to date, or an error description.

2. Repair a Corrupted MyISAM Table

REPAIR TABLE myapp.users;

The REPAIR TABLE command fixes corruption in MyISAM tables. It rebuilds indexes and recovers data from the .MYD data file.

3. Check All Tables in a Database with mysqlcheck

mysqlcheck -u root -p --check myapp

4. Repair All Tables in a Database

mysqlcheck -u root -p --repair myapp

Common Issues

"The storage engine for the table doesn't support repair"— InnoDB tables do not support REPAIR TABLE. For InnoDB corruption, use ALTER TABLE myapp.users ENGINE=InnoDB; to rebuild the table, or restore from a mysqldump backup. See MySQL: Table is marked as crashed.