MySQL error 1236 When using GTID
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction to MySQL Error 1236 with GTID
MySQL's Global Transaction Identifiers (GTIDs) bring about a refined way to handle replication, allowing for better replication failover and management capabilities. However, like any system, it is not without its problems. One commonly encountered error is MySQL error 1236, especially prevalent in GTID-based replication setups. This error is often associated with the inability of the slave server to retrieve, interpret, or properly apply the binary log from the master server.
Understanding Error 1236
MySQL error 1236 typically presents itself with a message similar to:
This error indicates issues with replication due to the binary logs on the master server being out of sync with what the slave expects. Specifically, it means that the slave has tried to do a log file operation for which it lacks the necessary binary log information.
Causes and Technical Explanations
Several factors can lead to this error, particularly when GTID is involved:
- Binary Log Deletion: If the binary log files on the master server are purged or deleted before the slave server read them, this error will occur. This can happen due to log rotation settings that are too aggressive.
- Incorrect GTID Position: If the slave's GTID position does not match any binary log on the master, the slave cannot figure out where to continue replication from.
- Out-of-sync Replication: Sometimes network issues or server crashes can lead to discrepancies in the replication stream.
- Misconfiguration: In some cases, incorrect configuration parameters related to logging and GTID can cause this problem.
Example Scenario
Imagine a scenario where the master is replicating transactions to the slave. The following sequence of events could provoke error 1236:
- The master writes transaction GTID
uuid:1-5into its binary logs. - The slave successfully replicates transactions
uuid:1-3. - Due to high transaction volume, the master's binary logs rotate, and
uuid:1throughuuid:3are purged. - The slave, upon its next attempt to replicate, searches for
uuid:4, but finds that the binary log starting withuuid:4has been purged. - Error 1236 is thrown due to the slave not finding the expected GTID sequence.
Resolving the Error
The approach to resolving MySQL error 1236 will depend on the root cause:
- Backup and Restore: If possible, restore the missing transactions by creating a new master from a backup that includes the lost transactions.
- Adjust Log Retention: Modify the master’s log retention policy to ensure logs are retained long enough for all slaves to process.
- Manual Intervention: Manually set the slave's replication to start from a position available in the master's binary logs. This can involve using
CHANGE MASTER TO ... MASTER_LOG_FILE=''...to reset the replication position. - Purging Incorrect Data: If the replication data is already inconsistent, you might need to skip transactions manually using
SET GLOBAL sql_slave_skip_counter.
Best Practices to Avoid Error 1236
- Adequate Backup: Regularly back up logs to ensure that missing transactions can be resurrected if needed.
- Log Expiry Configuration: Set appropriate values for
expire_logs_daysto avoid premature log purges. - Monitoring: Implement comprehensive monitoring that can alert you when binary logs approach their retention limits.
- Using
gtid_purgedandgtid_executed: Use these for GTID consistency checks.
Key Points Summary
| Key Point | Explanation | Recommendation |
| Error 1236 | Occurs when binary log files the slave needs are missing. | Ensure proper log retention and slave synchronization. |
| Causes | Log deletion, incorrect GTID position, out-of-sync objects. | Maintain backups and ensure correct GTID settings. |
| Resolution | Backup restore, log retention adjustment, manual intervention. | Quickly address and align master-slave setups. |
| Prevention | Use of expire_logs_days, backups, monitoring. | Set proper configurations and plan disaster recovery. |
Conclusion
MySQL error 1236 is a significant hindrance in GTID-based replication but is manageable with proactive configuration and maintenance practices. Correctly understanding MySQL binary logs' mechanisms and GTID functionalities can go a long way toward maintaining the integrity of your replication setup and minimizing downtime.
Related reading
- mysql error 1364 Field doesn't have a default values
- MySQL error 1449 The user specified as a definer does not exist
- Mysql error 1452 - Cannot add or update a child row a foreign key constraint fails
- MySQL error 2006 mysql server has gone away
- MySQL Error 'Access denied for user 'root''localhost
- MySQL error code, 1175 during UPDATE in MySQL Workbench
- MySQL Error Code 1118 Row size too large 8126. Changing some columns to TEXT or BLOB
- MySQL error code 1175 during UPDATE in MySQL Workbench

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.