How to fix ERROR 1035: Old key file; repair it in MySQL
MySQL Error 1035 appears when the MyISAM storage engine detects a corrupted or outdated .MYI key file. Quick repair using REPAIR TABLE or myisamchk restores access to your table and prevents data integrity issues.
Quick fix
Fixes 1035
mysqldump -u root -p database_name table_name > table_backup.sql- Back up the affected table immediately
- Attempt a quick repair with REPAIR TABLE
- Use REPAIR TABLE USE_FRM if QUICK fails
- Run a full REPAIR TABLE if necessary
mysqldump -u root -p database_name table_name > table_backup.sqlERROR 1035: Old key file; repair it
What this error means
MySQL Error 1035 (ER_OLD_KEYFILE) indicates that the .MYI index file for a MyISAM table is either corrupted or older than the .MYD data file. The MyISAM storage engine detected a mismatch between the index file metadata and the actual data file, which stops all read and write operations on that table until the indexes are rebuilt. This error is a safety mechanism that prevents MySQL from attempting queries on inconsistent indexes, which could return wrong results or cause data corruption.
Typical symptoms
- Queries on a specific table fail with "ERROR 1035: Old key file"
- INSERT or UPDATE operations hang or fail on affected tables
- SELECT queries return no results or error immediately
- MySQL error log shows multiple key file errors for the same table
- Application cannot connect to or access a specific table
Common causes
- Unclean MySQL shutdown (power loss, kill -9 signal, or crash) leaves the .MYI index file inconsistent with the data file
- Disk full conditions during write operations corrupt the index file before it is fully flushed
- File system errors or corruption affecting the .MYI index file specifically
- Manual file copying or moving of table files while MySQL is running
- Failed ALTER TABLE operations that leave the index file in an inconsistent state
- Running different MySQL versions on the same data directory without proper migrations
- Severe hardware failures or I/O errors on disk containing the index file
How to fix "ERROR 1035: Old key file; repair it"
Before attempting any repair, export the table using mysqldump to preserve your data:
mysqldump -u root -p database_name table_name > table_backup.sqlThis creates a SQL file with the table structure and data that you can restore if the repair fails.
Connect to MySQL and run the REPAIR TABLE command with the QUICK option to try a non-destructive repair:
REPAIR TABLE table_name QUICK;This tells MySQL to fix the .MYI index file without modifying the .MYD data file. It completes quickly and preserves all your data. Check the output for success or failure.
If the quick repair fails, try the USE_FRM option to rebuild the index file from the table definition file:
REPAIR TABLE table_name USE_FRM;Warning: This option tells MySQL to ignore the corrupted .MYI header. The AUTO_INCREMENT counter is lost and will be reset. Only use this after QUICK repair fails.
If both previous attempts fail, run a full repair operation (this takes longer):
REPAIR TABLE table_name;MySQL will perform a complete rebuild of the index file, scanning the data file thoroughly. Monitor disk space during this operation as it may create temporary files.
If the MySQL-based repairs fail, shut down MySQL and repair the table file directly:
# Stop MySQL
sudo systemctl stop mysql
# Quick recovery mode (fast, non-destructive)
myisamchk -r -q /var/lib/mysql/database_name/table_name.MYI
# If quick fails, use safe recovery mode
myisamchk --safe-recover /var/lib/mysql/database_name/table_name.MYI
# Restart MySQL
sudo systemctl start mysqlReplace paths based on your MySQL data directory location.
MySQL provides the mysqlcheck tool to identify and repair multiple tables at once:
# Repair a specific table
mysqlcheck -u root -p --auto-repair database_name table_name
# Repair all tables in a database
mysqlcheck -u root -p --auto-repair database_name
# Repair all tables in all databases
mysqlcheck -u root -p --auto-repair --all-databasesThe --auto-repair flag automatically runs REPAIR TABLE if CHECK finds corruption.
If repair attempts fail or report data loss, restore from your backup:
# Stop MySQL
sudo systemctl stop mysql
# Remove or rename corrupted files
sudo mv /var/lib/mysql/database_name/table_name.* /var/lib/mysql/database_name/table_name.corrupt/
# Start MySQL
sudo systemctl start mysql
# Restore from mysqldump backup
mysql -u root -p database_name < table_backup.sqlThis completely restores the table from your backup file.
Advanced notes
MyISAM is a legacy storage engine and Error 1035 is specific to MyISAM tables. Modern MySQL installations should use InnoDB instead, which includes built-in crash recovery and is less prone to corruption. If you have MyISAM tables, consider migrating to InnoDB using ALTER TABLE table_name ENGINE=InnoDB. This eliminates the risk of Error 1035 entirely.
For environments that must maintain MyISAM tables, schedule regular OPTIMIZE TABLE commands (weekly or after heavy write operations) to maintain index health. Enable innodb_file_per_table and use binary logging to protect against data loss. In production, implement automated backups (daily or more frequently) and test restore procedures quarterly.
The .MYI file is the key file that stores indexes, while the .MYD file contains actual row data. Error 1035 indicates the .MYI file is out of sync, not necessarily data loss. This is why REPAIR TABLE QUICK usually succeeds.
Disk space is critical during repairs: myisamchk and REPAIR TABLE may create temporary files equal to the size of the original data. Ensure your data directory has free space equal to 1.5x your table size before attempting repairs in production.
Frequently asked questions
- What does "1035" mean?
- MYD data file. The MyISAM storage engine detected a mismatch between the index file metadata and the actual data file, which stops all read and write operations on that table until the indexes are rebuilt. This error is a safety mechanism that prevents MySQL from attempting queries on inconsistent indexes, which could return wrong results or cause data corruption.
- How do I fix "1035"?
- MySQL Error 1035 appears when the MyISAM storage engine detects a corrupted or outdated .MYI key file. Quick repair using REPAIR TABLE or myisamchk restores access to your table and prevents data integrity issues.
- What causes "1035"?
- Unclean MySQL shutdown (power loss, kill -9 signal, or crash) leaves the .MYI index file inconsistent with the data file Disk full conditions during write operations corrupt the index file before it is fully flushed File system errors or corruption affecting the .MYI index file specifically
- Is the "1035" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐MySQL Official Documentation
- ๐MySQL 8.0 REPAIR TABLE Statement Documentation(Official Docs)
- ๐MySQL 8.4 How to Repair MyISAM Tables(Official Docs)
- ๐MariaDB Error 1035 Documentation(Official Docs)