MyISAMchk
Luke Hebert
- 2 minutes read - 251 wordsMyISAM tables store their index data in .MYI files alongside the data files. When those index files get corrupted, queries start failing or returning wrong results, and the fastest fix is to run myisamchk directly against the index files while MySQL is stopped.
Repairing MyISAM Index Files
The command below repairs all MyISAM index files in the ariella_info database directory:
myisamchk --repair /var/lib/mysql/ariella_info/*.MYIA few things to keep in mind before you run it:
- Stop MySQL first. Running
myisamchkwhile the server is active can cause further corruption. Usesystemctl stop mysqld(or the equivalent for your platform) before proceeding. - The
--repairflag tellsmyisamchkto rebuild the index. It is equivalent to--recoverbut uses a faster algorithm. If the standard repair does not resolve the issue, try--recoverinstead. - File permissions. Make sure the user running the command has read and write access to the
.MYIfiles. If you are running as root, you may need tochownthe files back tomysql:mysqlafterward.
Verifying the Repair
After the repair completes, myisamchk will print a status line for each file. Look for OK at the end of each line. If you see Error or Corrupt, the file may need a full rebuild:
myisamchk --check /var/lib/mysql/ariella_info/*.MYIOnce everything checks out, restart MySQL and confirm your queries are working as expected.
If the database is in use by an application, schedule the repair during a maintenance window. Stopping MySQL mid-transaction can leave other tables in an inconsistent state.