A MySQL replica stops with error 1236 while reading the source's binary log
Your error
Got fatal error 1236 from source when reading data from binary log: 'Could not find first log file name in binary log index file'3 more lines it can showFix it fast
Most common cause, 1 of 3The binary log file the replica needs was purged (file and position replication)
The source cannot send those events any more, so rebuild the replica from a consistent dump of the source. --source-data writes a CHANGE REPLICATION SOURCE TO statement with the matching coordinates into the dump.
# on the source host
mysqldump -u root -p --single-transaction --source-data=1 --all-databases > source.sql
# on the replica
mysql -u root -p -e "STOP REPLICA;"
mysql -u root -p < source.sql
mysql -u root -p -e "START REPLICA;"Short answer
Got fatal error 1236 from source when reading data from binary log means the source cannot send what the replica asks for. The quoted reason says why: a binary log file or GTIDs the replica needs were purged, or an event exceeds max_allowed_packet. Rebuild the replica or raise the limit, using 8.4 SOURCE and REPLICA statements. MySQL 8.4 and 9.7.
Which cause do you have?
On the replica, read the IO error and the position fields; on the source, list the binary logs it still has. The text in quotes after 'binary log:' picks the cause, and Auto_Position says whether GTIDs are in use. MySQL 5.7 printed from master in the same message; SHOW SLAVE STATUS and SHOW MASTER LOGS no longer exist in 8.4.
-- replica
SHOW REPLICA STATUS\G
-- look at Last_IO_Errno, Last_IO_Error, Source_Log_File, Read_Source_Log_Pos, Auto_Position
-- source
SHOW BINARY LOGS;Then find the line you see in this list and open its fix:
- 1The binary log file the replica needs was purged (file and position replication)
Last_IO_Error quotes Could not find first log file name in binary log index file, Auto_Position is 0, and the Source_Log_File value is missing from SHOW BINARY LOGS on the source - 2The source purged GTIDs the replica has not applied (GTID auto-positioning)
Last_IO_Error quotes Cannot replicate because the source purged required binary logs, Auto_Position is 1, and the message lists the missing transactions - 3An event in the binary log is bigger than max_allowed_packet
Last_IO_Error quotes log event entry exceeded max_allowed_packet; Increase max_allowed_packet on source
What does the error look like?
Got fatal error 1236 from source when reading data from binary log: 'Could not find first log file name in binary log index file'Got fatal error 1236 from source when reading data from binary log: 'Cannot replicate because the source purged required binary logs. Replicate the missing transactions from elsewhere, or provision a new replica from backup. Consider increasing the source's binary log expiration period.Got fatal error 1236 from source when reading data from binary log: 'log event entry exceeded max_allowed_packet; Increase max_allowed_packet on source'Got fatal error 1236 from master when reading data from binary log
Cause 1 of 3
The binary log file the replica needs was purged (file and position replication)
You seeLast_IO_Error quotes Could not find first log file name in binary log index file, Auto_Position is 0, and the Source_Log_File value is missing from SHOW BINARY LOGS on the source
Check
Error 1236 with this reason means the source no longer has the file the replica wants to continue from. Binary logs expire after binlog_expire_logs_seconds, 30 days by default, and PURGE BINARY LOGS removes them on request, so a replica that was stopped or far behind for longer has lost its place.
-- source
SHOW BINARY LOGS;
SELECT @@GLOBAL.binlog_expire_logs_seconds;Fix
The source cannot send those events any more, so rebuild the replica from a consistent dump of the source. --source-data writes a CHANGE REPLICATION SOURCE TO statement with the matching coordinates into the dump. The old CHANGE MASTER TO, RESET SLAVE and START SLAVE commands from older answers were removed in 8.4.
# on the source host
mysqldump -u root -p --single-transaction --source-data=1 --all-databases > source.sql
# on the replica
mysql -u root -p -e "STOP REPLICA;"
mysql -u root -p < source.sql
mysql -u root -p -e "START REPLICA;"Verify
Replica_IO_Running and Replica_SQL_Running both read Yes, and Last_IO_Errno is 0.
SHOW REPLICA STATUS\GConfirmed by dev.mysql.com
Cause 2 of 3
The source purged GTIDs the replica has not applied (GTID auto-positioning)
You seeLast_IO_Error quotes Cannot replicate because the source purged required binary logs, Auto_Position is 1, and the message lists the missing transactions
Check
With GTIDs, the replica sends the set of transactions it has, and the source must still hold every transaction outside that set. When those were purged, the source stops with this reason and logs the missing GTIDs in its error log. The message itself names the ways out: replicate the missing transactions from elsewhere, or provision the replica from a backup.
-- source
SELECT @@GLOBAL.gtid_purged;
-- replica
SELECT @@GLOBAL.gtid_executed;Fix
Rebuild the replica from a fresh dump of the source that carries the GTID set. RESET BINARY LOGS AND GTIDS clears the replica's own binary logs and GTID history first; never run it on a server that has running replicas of its own.
# on the source host
mysqldump -u root -p --single-transaction --set-gtid-purged=ON --all-databases > source.sql
# on the replica
mysql -u root -p -e "STOP REPLICA; RESET BINARY LOGS AND GTIDS;"
mysql -u root -p < source.sql
mysql -u root -p -e "CHANGE REPLICATION SOURCE TO SOURCE_AUTO_POSITION = 1; START REPLICA;"Verify
The replica reconnects, Retrieved_Gtid_Set grows, and Last_IO_Error stays empty.
SHOW REPLICA STATUS\GConfirmed by raw.githubusercontent.com
Cause 3 of 3
An event in the binary log is bigger than max_allowed_packet
You seeLast_IO_Error quotes log event entry exceeded max_allowed_packet; Increase max_allowed_packet on source
Check
Here the log is intact and only the size limit stops the transfer. A large row event, for example from a BLOB column or a big multi-row change, does not fit in the packet size the source allows, and the message names the source as the place to raise it. The default is 64 MB and the maximum is 1 GB.
-- source
SELECT @@GLOBAL.max_allowed_packet;Fix
Raise the limit on the source, persist it across restarts, and restart replication so a new connection picks it up.
-- source
SET PERSIST max_allowed_packet = 1073741824;
-- replica
STOP REPLICA;
START REPLICA;Verify
The replica gets past the event, and Read_Source_Log_Pos moves forward.
SHOW REPLICA STATUS\GConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Set binlog_expire_logs_seconds on the source longer than the longest time a replica may be stopped, and check it before maintenance windows.
- Alert on Replica_IO_Running not being Yes, so a stopped replica is noticed before its binary logs expire.
- Before running PURGE BINARY LOGS, confirm every replica has already read past the files you remove.
Sources
- MySQL 8.4 error reference: 1236 ER_SOURCE_FATAL_ERROR_READING_BINLOG
- MySQL 9.7 error reference
- MySQL server source: binlog sender reasons (8.4 branch)
- MySQL server source: client messages, ER_SOURCE_HAS_PURGED_REQUIRED_GTIDS (8.4 branch)
- MySQL 8.4: What is new (removed replication statements)
- MySQL 8.4: SHOW REPLICA STATUS
- MySQL 8.4: mysqldump (--source-data, --set-gtid-purged)
- MySQL 8.4: RESET BINARY LOGS AND GTIDS
- MySQL 8.4: CHANGE REPLICATION SOURCE TO
- MySQL 8.4: Binary logging options (binlog_expire_logs_seconds)
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, QistLock, ShopGo.