Databases

MySQL replica error 'Could not find first log file name in binary log index file' after scripted binlog rotation during backup

Environment

Environment

Primary MySQL 8.0.32 on CentOS 7, replica MySQL 8.0.32 on CentOS 7. Primary runs custom backup script that rotates binary logs via mysqladmin flush-logs and moves old binlogs off to backup storage; replication uses GTID-based replication with replication user having REPLICATION SLAVE privileges.

Symptoms

Symptoms

Replica IO thread stops with error: 'Could not find first log file name in binary log index file' and SQL thread lags. Replica reports 'Got fatal error 1236 from master during replication'. The replica's relay logs grow but no new events apply.

Observations

Observations

On primary, binlog index (.index) contains references to moved files but rotated file names differ from replica's expected; backup script moved binlog files without updating master.info or without using mysqladmin flush-logs + purge. The replica's SHOW SLAVE STATUS shows Master_Log_File referencing a file that no longer exists on primary and MASTER_POS_WAIT returns immediately with error.

Already attempted

Already attempted

Tried START SLAVE, CHANGE MASTER TO MASTER_LOG_FILE='...' MASTER_LOG_POS=..., but primary's current binlog set doesn't include the requested file. Restoring moved binlog files to primary's binlog dir briefly allowed replica to resume but subsequent replication jumped to a different GTID sequence and stalled again.

Question

Question

How to safely reconcile the replica without data loss when primary's old binlog files were moved by the backup script? What steps to recover replication and prevent recurrence?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Backup script moved/purged binary logs on master while replicas had not yet retrieved required files 95%
Binlog index file updated incorrectly (file rename) causing mismatch between actual binlog filenames and index entries 40%
Replica's relay log corruption after abrupt disk operation or improper restart 25%

Summary

The backup script likely moved binary logs before replicas had fetched/applied them or without coordinating purge/expiration, leaving replicas referencing missing files. With GTID enabled, manual binlog position adjustment can work if corresponding transactions are still available; otherwise you must re-provision replica with a fresh base backup from the primary at a known GTID set. Restoring moved binlogs temporarily allowed catch-up, indicating events existed. The safest recovery is to re-bootstrap the replica with consistent backup (mysqldump or xtrabackup) and set GTID_PURGED appropriately. Prevent recurrence by using mysql's PURGE BINARY LOGS TO or setting expire_logs_days or using mysqladmin flush-logs + safe copy.

Suggested Fixes

Diagnostic step 1
Stop replication on replica and back up replica data directory (for safety, do not overwrite).
Diagnostic step 2
If you still have the original moved binlog files, restore them into the master's binlog directory (read-only restore) so replica can catch up; monitor SHOW SLAVE STATUS.
Diagnostic step 3
If binlogs are permanently missing, take a fresh consistent backup from primary (xtrabackup or mysqldump with FLUSH TABLES WITH READ LOCK) and reinitialize the replica using that backup and GTID-based replication.

Continue troubleshooting

Matched from the title, description and tags