Start with a backup, then check the table before you change it. On Linux, the usual fix for a damaged MyISAM table is mysqlcheck --repair or REPAIR TABLE, while a damaged InnoDB table is normally restored from backup or rebuilt from a dump or replica. InnoDB lives inside the shared tablespace or its own .ibd files and has no in-place REPAIR TABLE mode for secondary index corruption. The storage engine, not the operating system, dictates which repair path works.

That distinction matters because the word "repair" hides two very different jobs. One is fixing index pages in a storage engine that supports in-place repair, such as MyISAM or Aria. The other is recovering data after physical or logical corruption in InnoDB, where the engine usually stops rather than guesses. The steps below apply to MySQL 8.0 and 8.4 as the current reference versions, and they mention MariaDB differences where they change the action. The reference date is November 13, 2026; version behavior can shift, so confirm your server version with mysql --version before running anything.

Prerequisites: root access, free disk space, and a tested backup

Repairing a table is a write operation, and a failed repair can truncate data. Before touching the server, confirm four things.

You have shell access and an account with SHUTDOWN, PROCESS, and table privileges, or root inside mysql. You know the storage engine. Run SHOW TABLE STATUS or query information_schema.tables and read the ENGINE column. You have free space at least equal to the damaged table's size plus some overhead, because repair may create temporary files. Check with df -h on the data directory, commonly /var/lib/mysql. You have a recent logical or physical backup, and you have restored it at least once in practice.

Take a fresh dump before repair if the table still reads, so a failed repair doesn't destroy evidence:

For an InnoDB table this dump is also your best recovery asset. If the table is already unreadable, copy the files from the data directory while the server is stopped, or take a filesystem snapshot if your storage supports it. A snapshot is not a substitute for a tested backup, but it does give you a rollback point.

A quick integrity check tells you how bad things are:

CHECK TABLE is read-only for InnoDB and reports whether the table is marked as crashed. For MyISAM it can also find link errors. Do not add FOR UPGRADE unless you are actually upgrading. Then check the error log, typically /var/log/mysql/error.log, for the message that prompted you. "Table is marked as crashed and should be repaired" is specific to MyISAM and Aria. An InnoDB error such as "Database page corruption on disk or a failed file read" points to a different path.

Step 1: Identify the engine and the failure type

Run:

Read the ENGINE value and match it to a repair method.

MyISAM or Aria: in-place REPAIR TABLE works. Aria appears in MariaDB and behaves similarly for this purpose. InnoDB or XtraDB: REPAIR TABLE usually returns an error or does nothing useful. Recovery means rebuilding, dumping, or restoring. MEMORY: content is lost on restart; there is nothing durable to repair. NDB (MySQL Cluster): MySQL Enterprise tools manage it; do not use standard REPAIR TABLE.

Also distinguish symptoms. Random server crashes with InnoDB usually point to memory, storage, or kernel issues rather than the table itself. Corrupt .ibd files often follow a hard power loss or a full disk. MyISAM crashes after an unclean shutdown are common because that engine has no crash recovery log. Treating the cause, not just the table, prevents a repeat.

Stop conditions worth naming: if dmesg shows I/O errors, if the filesystem is read-only after boot, or if SMART data indicates a failing disk, stop and replace the storage before running repairs. Repairing a table on a dying disk wastes time and risks data.

Step 2: Repair a MyISAM or Aria table with mysqlcheck or SQL

mysqlcheck is the command-line wrapper around the same checks and repairs that the SQL statements perform. It runs while the server is online and is the most direct fix for a crashed MyISAM table.

Basic repair of one table:

Table-level version:

mysqlcheck by default repairs only tables that need it. You can combine checks:

Inside MySQL, the equivalent is:

The result column shows status with values such as OK, Table is already up to date, or an error like Corrupt. A successful run means the table's internal links are consistent. It does not prove your application data is semantically correct, and it does not protect against a future crash on the same table.

MySQL 8.0 adds options for MyISAM that you rarely need. REPAIR TABLE tablename QUICK skips the index rebuild and fixes only link errors; EXTENDED rebuilds indexes row by row and is slower. Use QUICK first if you want a fast pass, then fall back to a full repair if it reports errors. USE_FRM recreates the index file from the .frm definition and is only appropriate when the .MYI file is gone or unusable; it can lose rows though, so keep the backup.

Check success by running CHECK TABLE again and confirming OK. Then query a few known rows and compare counts with your backup. A repaired table that returns fewer rows than expected is a data-loss event, not a success.

For MyISAM tables you can also repair offline. Stop MySQL with systemctl stop mysql (or mysqld), then run myisamchk against the .MYI file:

myisamchk is faster than online repair for large tables, but it must not run while the server has the table open. If you go this route, restart the server and run CHECK TABLE afterward.

Step 3: What to do when the table is InnoDB

InnoDB handles crash recovery itself through its redo log, so most "corruption" messages after a crash are actually a failed recovery rather than a damaged table. Check the error log for the precise message. The engine will typically refuse to start or refuse to open the table if it detects a checksum mismatch.

Try a soft restart first, since it reverses the effect of an unclean shutdown without touching data files:

If that fails with a crash-recovery error, start with innodb_force_recovery set to a low value, typically 1. The variable goes in the [mysqld] section of your MySQL config, commonly /etc/mysql/mysql.conf.d/mysqld.cnf or a file under /etc/my.cnf.d/, depending on distribution. Restart the server and dump the table immediately:

Then stop the server, remove innodb_force_recovery, and restore the dump into a rebuilt table. This sequence works because force recovery mode tolerates mild inconsistency but blocks writes, so it is a read-only rescue path, not a fix.

If the dump fails even at higher recovery levels, escalate cautiously. Levels 1 through 3 are the safe range for most data recovery; levels 4 through 6 can cause page inconsistencies and are a last resort before professional data recovery. Do not run production traffic against a server in force recovery, and do not assume a higher level is better. Each step trades safety for the ability to start.

There is a distinct tool for the rare case of an offline .ibd file that needs rebuilding: ibd2sdi extracts dictionary data from a tablespace file in MySQL 8.0. It is a structural inspection tool, not a repair tool, and it does not replace a dump-and-restore. If the system tablespace itself is damaged, ordinary table repair is the wrong layer. In that scenario, restoring from a physical backup or rebuilding on a replica is the realistic option.

MariaDB differs in placement, not principle. Its equivalent config is /etc/mysql/mariadb.conf.d/ and the same innodb_force_recovery variable applies. MariaDB also includes innochecksum for offline page checks, which MySQL ships too; it verifies page checksums in an .ibd file and helps you localize corruption before deciding on a restore.

Step 4: Rebuild the table when the definition is suspect

Sometimes the rows are fine and the table structure is broken. A known symptom is an error mentioning the .frm file or an "incorrect information in file" message on older MySQL versions. In MySQL 8.0 the dictionary is data-dictionary based, so a .frm error is less common but still possible after downgrades or file-level copies.

A safe online rebuild, when the table is MyISAM and readable:

For any engine where you want to force a copy, use:

Both statements rewrite the table. ALTER TABLE ... ENGINE=InnoDB on an already-InnoDB table is effectively a rebuild and is a standard way to clean InnoDB page fragmentation. Always dump first, because a rebuild on a corrupted table can fail partway and leave the table unusable. If ALTER TABLE fails, restore the dump rather than trying another rebuild.

On MariaDB older than 10.6, users occasionally hit the .frm recovery pattern that relies on REPAIR TABLE ... USE_FRM. That pattern is less relevant now. Treat it as a legacy fallback with a backup in hand, and confirm the MariaDB version first.

Step 5: Recover a table you can no longer read

If CHECK TABLE reports corruption and a dump fails, the job shifts from repair to salvage. The order of attempts matters because each one can change data.

First, try a SELECT * into an outfile with a tolerant client. If the server can read some rows, dump them and accept partial recovery:

The --force flag keeps going after errors and captures what it can. Then import into a fresh table with the same schema, check counts, and compare against your backup. For InnoDB, importing a recovered dump into a new table is usually cleaner than attacking the original .ibd.

Second, if only part of a table is damaged and you can identify the boundary, restore individual rows from the backup where they exist, and use the partial dump for the gaps. Make the gap explicit in your records: partial recovery is common and acceptable, but it must be reported to whoever owns the data.

Third, if the database cannot start at all, restore from a physical backup or promote a replica. This is where the tested backup pays for itself. Do not attempt a repair on the system tablespace without a verified backup and, ideally, help from someone who has done it before.

A worked sense of scale: suppose a 40 GB InnoDB table is corrupted and a dump with --force recovers 39.6 GB. That is about 1 percent missing, roughly 400 MB, which could be thousands of rows. You cannot assume the missing rows are unimportant because they may be the recent ones. Restore from backup first if it is current; use the partial dump only for the window the backup doesn't cover.

Verify the repair and reset the evidence trail

A repair is complete only when three checks pass.

1: CHECK TABLE tablename; returns OK. 2: A row count and a sample of recent rows match your backup or your application's expectations. 3: The application performs a read and write against the table successfully.

Then record what happened: the error-log message, the engine, the command you ran, and the number of rows before and after. This matters because a repaired MyISAM table that crashes again may indicate a failing disk, and an InnoDB table that corrupts twice is a strong signal to move that data to a properly managed replica or a newer server. Production MySQL is best run on supported versions with InnoDB, and MyISAM repair should be treated as a bridge, not a plan.

Reset the evidence trail once data is confirmed. Delete or archive the before-repair dump according to your retention rules, and confirm that the crash didn't change the table's auto-increment counter or its row format in a way that breaks expectations. Both changes are minor but worth checking.

Before you repair: lock behavior and online considerations

Repairing a MyISAM table with REPAIR TABLE takes a write lock on that table for the duration, so concurrent writes wait. For large tables, schedule it outside peak hours and tell applications that writes may pause. mysqlcheck respects the same locks because it issues the same statements. A read-heavy workload can usually continue.

On a replica, a repair makes the replica diverge from the primary until you fix the primary too. Repair the source of truth, then let replication catch up, or rebuild the replica. Do not run repairs on a replica and assume the problem is solved.

For InnoDB, a dump-and-restore cycle is a logical operation that you can run against a live server with --single-transaction, which gives a consistent snapshot without locking writers. The restore into a new table still takes an exclusive metadata lock for the swap, so plan that step.

When to stop and call in help

Corruption that keeps returning, errors in the InnoDB system tablespace, failure to start even with low force-recovery settings, and any sign of failing storage are all signals to stop. At that point the work becomes data recovery, and the safest move is to protect the current files: stop writes, copy the data directory or take a snapshot, and restore from the most recent verified backup. Handle the storage problem before another repair attempt. If the data is critical and the backup is older than the gap, a professional data-recovery service is a legitimate next step, but preserve the original files first.