# ERROR 1220 (HY000): 执行命令'SHOW BINARY LOGS'时出错：二进制日志文件'mysql-bin.000123'已损坏

- **ID:** `database/mysql-binary-log-corruption`
- **领域:** database
- **类别:** data_error
- **错误码:** `1220`
- **验证级别:** ai_generated
- **修复率:** 72%

## 根因

MySQL二进制日志文件因磁盘故障、意外关闭或不完整写入而损坏，阻止了复制或日志检查。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| MySQL 8.0 | active | — | — |
| MySQL 8.4 | active | — | — |
| MySQL 9.0 | active | — | — |
| MariaDB 10.11 | active | — | — |
| MariaDB 11.4 | active | — | — |

## 解决方案

1. ```
   Skip the corrupted binary log file on the replica by setting the next log position. Example: STOP SLAVE; CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000124', MASTER_LOG_POS=4; START SLAVE;
   ```
2. ```
   If the corruption is isolated, use mysqlbinlog to extract events up to the corruption point: mysqlbinlog --stop-position=123456 mysql-bin.000123 > partial.sql; then apply the partial log to the replica.
   ```
3. ```
   Purge the corrupted binary log file after ensuring all replicas have caught up: PURGE BINARY LOGS TO 'mysql-bin.000124'; Then reset the master log: RESET MASTER;
   ```

## 无效尝试

- **Delete all binary log files and restart MySQL.** — This breaks replication if replicas rely on those logs; it also removes forensic evidence. Use PURGE BINARY LOGS instead. (90% 失败率)
- **Ignore the corrupted log and continue without fixing replication.** — Replication will stall at the corrupted log file; the replica will not apply further changes until the issue is resolved. (95% 失败率)
