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.
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.
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.
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.
EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL