MySQL table corruption can prevent an application from reading or writing data. Recovery depends on the storage engine and the underlying failure, so confirm the diagnosis and preserve recovery data before attempting a repair.
Common causes of MySQL database corruption
Storage failures, damaged filesystems, software faults and interrupted operations can cause corruption. An application error or failed login alone does not prove that a database is corrupt.
Check disk health, free space and the server’s error log. Use the log location configured for your installation rather than assuming a universal path.
Methods to identify corruption
Record the affected database, tables, engine and exact error. With appropriate database permissions, inspect table engines:
SELECT TABLE_NAME, ENGINE
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'example_database';Replace the example database name with the affected database. A targeted check for a confirmed MyISAM table can be run with:
mysqlcheck -u database_user -p --check example_database example_tableUse the actual account and names. Enter the password at the prompt. Checks can affect availability; avoid indiscriminate scans of every production database.
How to repair a corrupted MySQL database
Preserve the current data and a verified recovery backup before changing it. If the server cannot produce a reliable logical backup, arrange a suitable stopped-server or consistent storage recovery copy with the administrator.
For a confirmed MyISAM table, a targeted repair may be appropriate:
mysqlcheck -u database_user -p --repair example_database example_tableReview the result and verify the application’s data. Do not run myisamchk against files that the server is still accessing.
REPAIR TABLE and mysqlcheck --repair do not repair InnoDB tables. Do not apply an automatic repair to every database or delete InnoDB data files.
For InnoDB corruption, use the vendor’s InnoDB recovery guidance with a database administrator. Forced recovery is for extracting salvageable data, not normal operation. Restore verified data into a suitable recovery environment and test it before replacing the live database.
Preventing future corruptions
Maintain tested off-server backups, monitor storage health and use supported database updates through the server’s management platform. Address the underlying failure before returning the database to service. A successful repair message is not a substitute for checking data completeness.