嘗試啟動 MySQL 失敗,錯誤日誌顯示:
mysqld: File '.\mysql-bin.000370' not found (Errcode: 2) [ERROR] Failed to open log (file '.\mysql-bin.000370', errno 2) [ERROR] Could not open log file [ERROR] Can't init tc log [ERROR] Aborting
原因:mysql-bin.index 索引檔記錄了 mysql-bin.000370,但實體檔案遺失/損壞 (可能因磁碟滿、手動刪除、遷移未帶走)。
cd /var/lib/mysql (或 C:\ProgramData\MySQL\MySQL Server 8.0\Data\)mysql-bin.index,刪除缺失檔案那一行 (如 .\mysql-bin.000370)mysql-bin.* 檔案 (含 .index):**會丟失未同步的主從複制座標,謹慎使用**systemctl start mysqldmysql -u root -p RESET MASTER; -- 會刪除所有 binlog 並重置 index,產生 mysql-bin.000001
| 用途 | 說明 |
|---|---|
| 主從複制 | Slave 從 Master 拉取 Binlog 重放,實現資料同步 |
| 時間點恢復 (PITR) | 全量備份 + Binlog 重放,恢復至任意秒 |
[mysqld] # 保留 3 天 (動態生效,無需重啟) expire_logs_days = 3 # 或運行時動態設定 SET GLOBAL expire_logs_days = 3; # 單檔上限 max_binlog_size = 100M
mysqlbinlog mysql-bin.000001 mysqlbinlog --start-position=107 --stop-position=500 mysql-bin.000001 > partial.sql
sync_binlog=1、innodb_flush_log_at_trx_commit=1 確保不丟交易。expire_logs_days 生效狀況,防止手動刪除導致 index 不一致。