# ERROR 1220 (HY000): Error when executing command 'PURGE BINARY LOGS': Could not find target log file mentioned in the file index

- **ID:** `database/mysql-binlog-purge-failure`
- **Domain:** database
- **Category:** data_error
- **Error Code:** `1220`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The binary log file specified in the PURGE BINARY LOGS command does not exist in the binary log index file, often because it was manually deleted or the index file is corrupted.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| MySQL 5.7 | active | — | — |
| MySQL 8.0 | active | — | — |
| MySQL 8.4 | active | — | — |
| MariaDB 10.5 | active | — | — |
| MariaDB 10.6 | active | — | — |

## Workarounds

1. **Rebuild the binary log index file by listing all existing binlog files: `ls -1 /var/lib/mysql/mysql-bin.* > /var/lib/mysql/mysql-bin.index` and ensure the file permissions are correct. Then retry PURGE BINARY LOGS.** (85% success)
   ```
   Rebuild the binary log index file by listing all existing binlog files: `ls -1 /var/lib/mysql/mysql-bin.* > /var/lib/mysql/mysql-bin.index` and ensure the file permissions are correct. Then retry PURGE BINARY LOGS.
   ```
2. **Use RESET MASTER (carefully, as it removes all binlogs) to clean the index and start fresh. Only do this if you don't need point-in-time recovery: `RESET MASTER;`** (90% success)
   ```
   Use RESET MASTER (carefully, as it removes all binlogs) to clean the index and start fresh. Only do this if you don't need point-in-time recovery: `RESET MASTER;`
   ```
3. **If a specific binlog file is missing, identify the gap and use FLUSH LOGS to create a new log, then purge up to that new log: `FLUSH LOGS; PURGE BINARY LOGS TO 'mysql-bin.000new';`** (75% success)
   ```
   If a specific binlog file is missing, identify the gap and use FLUSH LOGS to create a new log, then purge up to that new log: `FLUSH LOGS; PURGE BINARY LOGS TO 'mysql-bin.000new';`
   ```

## Dead Ends

- **Run PURGE BINARY LOGS TO 'mysql-bin.000999' again with a different filename** — If the index file is corrupted, any filename will fail with the same error until the index is rebuilt (90% fail)
- **Delete the binary log index file manually and restart MySQL** — Deleting the index file without rebuilding it will cause MySQL to fail to start or lose track of all binlogs (95% fail)
- **Set expire_logs_days to 0 to disable purging** — This only stops automatic purging; the manual PURGE command will still fail due to the index issue (70% fail)
