Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Databases and Redis

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 show

Fix it fast

Most common cause, 1 of 3

The 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.

Fix
# 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;"
Did this fix it?
Full steps for this cause: check, fix, verify

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.

  • Applies to MySQL 8.4 LTS source and replica, MySQL 9.7 LTS (same error 1236 text)
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
-- 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:

  1. 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
  2. 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
  3. 3An event in the binary log is bigger than max_allowed_packetLast_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.

Check
-- 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.

Fix
# 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.

Verify
SHOW REPLICA STATUS\G

Confirmed by dev.mysql.com

Did this fix it?

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.

Check
-- 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.

Fix
# 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.

Verify
SHOW REPLICA STATUS\G

Confirmed by raw.githubusercontent.com

Did this fix it?

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.

Check
-- 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.

Fix
-- 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.

Verify
SHOW REPLICA STATUS\G

Confirmed by raw.githubusercontent.com

Did this fix it?

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

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.