[MySQL] MySQL主从同步报错1236解决

记一次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主机,执行命令查看对应的报错日志的结束位置

[root@mysqlmaster2 mysql]# mysqlbinlog --no-defaults mysql-bin.001359 >> /tmp/123.log
[root@mysqlmaster2 mysql]# vi /tmp/123.log 
[root@mysqlmaster2 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 COMPLETION_TYPE=@OLD_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>

 

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值