[MySQL] MySQL主從同步報錯1236解決
阿新 • • 發佈:2018-12-19
記一次MySQL主從同步1236報錯檔案解決。
報錯:
Slave同步失敗報錯1236,日誌
mysql> show slave status \G *************************** 1. row *************************** Slave_IO_State: Master_Host: 10.168.1.8 Master_User: replication Master_Port: 3306 Connect_Retry: 30 Master_Log_File: mysql-bin.001359 Read_Master_Log_Pos: 61919961 Relay_Log_File: mysql-relay-bin.003719 Relay_Log_Pos: 4 Relay_Master_Log_File: mysql-bin.001359 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 61919961 Relay_Log_Space: 120 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 1236 Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Client requested master to start replication from position > file size; the first event 'mysql-bin.001359' at 61919961, the last event read from './mysql-bin.001359' at 4, the last byte read from './mysql-bin.001359' at 4.' Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 2 Master_UUID: 48a46c0c-eead-11e6-a73a-005056b6633d Master_Info_File: /data/mysql/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: 181105 08:26:10 Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 1 row in set (0.00 sec) mysql>
這種報錯可能的原因是主庫意外重啟,意外發生前主庫在一個binlog下面日誌寫入因為意外中斷,待重新起來的時候會開啟一個新的binlog從0開始寫。但是這件事情Slave並不知道,它還在一直同步前一個binlog,直到pos位置id大於binlog檔案位置上限觸發告警。
解決:
登入到Master主機,執行命令檢視對應的報錯日誌的結束位置
[[email protected] mysql]# mysqlbinlog --no-defaults mysql-bin.001359 >> /tmp/123.log
[[email protected] mysql]# vi /tmp/123.log
[ [email protected] mysql]# tail -f /tmp/123.log
insert into tb_o2n2 (device_o2_id,type,value,rectime)values(1,"N2",0,"2018-11-05 00:15:31.550817")
/*!*/;
# at 61918946
#181105 0:15:36 server id 2 end_log_pos 61918977 CRC32 0xc9906a5c Xid = 157867719
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET [email protected]_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
發現end_log_pos的值為61918977,比報錯日誌的位置值61919961要小,直接從這個位置開始重新配置主從:
去Slave上執行
mysql> stop slave;
Query OK, 0 rows affected (0.03 sec)
mysql> CHANGE MASTER TO
-> MASTER_HOST="192.168.1.8",
-> MASTER_USER="replication",
-> MASTER_PASSWORD="******",
-> MASTER_LOG_FILE="mysql-bin.001359",
-> MASTER_LOG_POS=61918977;
Query OK, 0 rows affected, 2 warnings (0.16 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql>
主從同步狀態恢復成功
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.8
Master_User: replication
Master_Port: 3306
Connect_Retry: 30
Master_Log_File: mysql-bin.001360
Read_Master_Log_Pos: 32879427
Relay_Log_File: mysql-relay-bin.000003
Relay_Log_Pos: 1526424
Relay_Master_Log_File: mysql-bin.001360
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1526261
Relay_Log_Space: 32879926
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 2849
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
Master_UUID: 48a46c0c-eead-11e6-a73a-005056b6633d
Master_Info_File: /data/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: System lock
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
mysql>