This replication error occurs on MySQL slaves when the master cannot send binary log events due to packet size mismatches, corrupted logs, or missing binary log files. It typically requires resynchronizing the replication connection or adjusting packet size settings.
ERROR 1236 is a fatal replication error that occurs on the slave (replica) server when the replication I/O thread encounters a problem reading binary log events from the master. This is one of the most common MySQL replication failures. The error can originate from several distinct issues: binary log packets that exceed the maximum allowed size (max_allowed_packet mismatch between master and slave), corrupted or truncated binary log files on the master (usually from crashes without proper sync_binlog settings), missing binary log files that the slave still requires, or impossible replication positions that reference non-existent binary log offsets. When this error occurs, the slave's I/O thread stops, halting all replication until you intervene. The slave becomes out-of-sync with the master, potentially leading to data inconsistency if transactions continue on the master while the slave is stalled.
First, stop the slave to prevent further errors and lock the slave status:
STOP SLAVE;Then check the current replication status:
SHOW SLAVE STATUS\GLook for:
- Last_IO_Error: The specific error message
- Master_Log_File: The binary log file the slave was trying to read
- Read_Master_Log_Pos: The position where it failed
- Relay_Master_Log_File: The last successfully processed master log
This is the most common cause. The slave cannot receive packets larger than its max_allowed_packet setting.
On the master, check:
SHOW VARIABLES LIKE 'max_allowed_packet';On the slave, check:
SHOW VARIABLES LIKE 'max_allowed_packet';
SHOW VARIABLES LIKE 'slave_max_allowed_packet';If the master's max_allowed_packet is larger than the slave's, increase the slave's setting.
To fix (slave configuration):
Edit your slave's MySQL configuration file (/etc/mysql/mysql.conf.d/mysqld.cnf or /etc/my.cnf):
[mysqld]
max_allowed_packet = 1G
slave_max_allowed_packet = 1GThen restart MySQL on the slave:
sudo systemctl restart mysqlFor MySQL 5.6.6+, the slave_max_allowed_packet variable (default 1GB) overrides max_allowed_packet for replication threads, which is safer.
The slave may be trying to read a binary log file that no longer exists. Check which binary logs are available on the master:
On the master, run:
SHOW BINARY LOGS;
-- or in older MySQL versions:
-- SHOW MASTER LOGS;From the slave's SHOW SLAVE STATUS output, note the Master_Log_File value. If that file is not in the master's list, the logs were purged.
Check expiration settings on master:
SHOW VARIABLES LIKE 'expire_logs_days';
-- MySQL 8.0.3+:
-- SHOW VARIABLES LIKE 'binlog_expire_logs_seconds';If logs are being purged too aggressively, increase this value on the master:
[mysqld]
expire_logs_days = 30 -- Keep logs for 30 days (MySQL 5.7)
-- Or in MySQL 8.0.3+:
binlog_expire_logs_seconds = 2592000 -- 30 days in secondsIf binary logs are already missing, you must rebuild the slave from a fresh backup (see Advanced Notes).
If the binary log file is missing or corrupted and you've verified that binary logs exist on the master, move the slave to the next available binary log file:
First, check what binary logs are available on the master:
SHOW BINARY LOGS;Then on the slave, move to the first available binary log with position 4 (the start of each binary log file):
STOP SLAVE;
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000712', MASTER_LOG_POS=4;
START SLAVE;Replace mysql-bin.000712 with the first available binary log from your master's SHOW BINARY LOGS output.
Verify replication resumed:
SHOW SLAVE STATUS\GBoth Slave_IO_Running and Slave_SQL_Running should show Yes.
Warning: This approach skips any transactions from the missing binary log. The slave and master may be momentarily inconsistent. This is acceptable only if:
- You're willing to tolerate a brief data inconsistency
- The skipped transactions are not critical
- You plan to verify data consistency afterward (see Advanced Notes)
Prevent future binary log corruption by ensuring the master durably writes binary logs to disk:
On the master, check:
SHOW VARIABLES LIKE 'sync_binlog';
SHOW VARIABLES LIKE 'binlog_cache_size';
SHOW VARIABLES LIKE 'binlog_stmt_cache_size';The key setting is sync_binlog:
- sync_binlog = 0 (default): OS controls when binlogs flush to disk (risky - data loss on crash)
- sync_binlog = 1: Every transaction commits to disk before returning success (safe but slower)
- sync_binlog = N (N > 1): Every Nth transaction syncs (compromise between safety and performance)
For production databases, enable safe binary log syncing:
Edit the master's MySQL configuration:
[mysqld]
sync_binlog = 1Also verify innodb_flush_log_at_trx_commit = 1 for full ACID compliance:
SHOW VARIABLES LIKE 'innodb_flush_log_at_trx_commit';If not set to 1, add to configuration:
[mysqld]
innodb_flush_log_at_trx_commit = 1Restart MySQL on the master:
sudo systemctl restart mysqlNote: Setting sync_binlog = 1 impacts write performance (typically 5-10% slower), but is essential for replication reliability.
After resuming replication, verify that master and slave are consistent. Data may have diverged if you skipped binary logs.
Option 1: Quick check using checksums (Percona Toolkit)
If you have Percona Toolkit installed:
pt-table-checksum h=master-host --max-lag=60 --no-check-binlog-formatThis compares master and slave data and reports differences.
Option 2: Manual consistency check
On both master and slave, run:
SHOW MASTER STATUS\G -- On master
SHOW SLAVE STATUS\G -- On slaveEnsure the slave's Exec_Master_Log_Pos equals the master's Position, indicating the slave has caught up.
For specific tables, compare row counts:
SELECT COUNT(*) FROM important_table;If inconsistencies exist and the data is critical, you may need to rebuild the slave from a backup.
Rebuilding slave from backup: If you cannot skip binary logs (too many transactions lost) or data consistency is critical, rebuild the slave from a master backup using mysqldump or Percona XtraBackup.
Using mysqldump with --master-data:
mysqldump --skip-lock-tables --single-transaction --flush-logs --master-data=2 -h master-host -u root -p --all-databases > backup.sql
mysql -h slave-host -u root -p < backup.sql
# Then start replication with the position from backup.sqlUsing Percona XtraBackup (faster for large databases):
xtrabackup --backup --target-dir=/backup --host=master-host --user=root --password=pass
xtrabackup --prepare --target-dir=/backup
# Copy to slave and restore, then start replicationGTID replication: In MySQL 5.6+ with GTIDs enabled, use:
CHANGE MASTER TO MASTER_HOST='master', MASTER_USER='repl', MASTER_PASSWORD='password', MASTER_AUTO_POSITION=1;
START SLAVE;The MASTER_AUTO_POSITION=1 setting handles position changes automatically, reducing manual intervention.
Encrypted binary logs (MySQL 8.0): If the master has encrypted binary logs, AWS DMS and some replication tools fail at initialization. Decrypt logs before replication or use a dedicated replication user with binary log decryption privileges.
Monitoring replication: Set up alerts for replication lag to catch error 1236 early:
-- Monitor Seconds_Behind_Master
SHOW SLAVE STATUS\G | grep Seconds_Behind_Master;
-- 0 = slave is caught up
-- NULL = replication is broken (slave stopped)
-- > 0 = slave is laggingCommon misconfiguration: Slave's server_id must differ from master's:
SHOW VARIABLES LIKE 'server_id';
-- Should be different on master vs slaveMulti-source replication: In MySQL 5.7+, if using multi-source replication (replicating from multiple masters), error 1236 must be fixed per channel:
SHOW SLAVE STATUS FOR CHANNEL 'channel_name'\G
CHANGE MASTER TO MASTER_LOG_FILE='...', MASTER_LOG_POS=4 FOR CHANNEL 'channel_name';EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL