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

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/wawa8899/article/details/83746594

记一次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>

 

 

展开阅读全文

mysql主从同步报错

02-13

rn120213 11:53:51 [ERROR] Failed to open log (file './localhost-relay-bin.000018', errno 2)rn120213 11:53:51 [ERROR] Failed to open the relay log 'FIRST' (relay_log_pos 4)rn120213 11:53:51 [ERROR] Could not open log filern120213 11:53:59 [ERROR] Failed to open log (file './localhost-relay-bin.000018', errno 2)rn120213 11:53:59 [ERROR] Failed to open the relay log 'FIRST' (relay_log_pos 4)rn120213 11:53:59 [ERROR] Could not open log filern120213 12:59:50 [ERROR] Error reading master configurationrn120213 13:00:39 [ERROR] Failed to open log (file './localhost-relay-bin.000018', errno 2)rn120213 13:00:39 [ERROR] Failed to open the relay log 'FIRST' (relay_log_pos 4)rn120213 13:00:39 [ERROR] Could not open log filern120213 13:00:42 [ERROR] Error reading master configurationrn120213 13:00:42 [ERROR] Error reading master configurationrn120213 13:00:43 [ERROR] Error reading master configurationrn120213 13:00:44 [ERROR] Error reading master configurationrn120213 13:00:44 [ERROR] Error reading master configurationrn120213 13:00:45 [ERROR] Error reading master configurationrn120213 13:00:48 [ERROR] Error reading master configurationrn120213 13:13:18 [ERROR] Error reading master configurationrn120213 13:14:37 [ERROR] Error reading master configurationrn120213 13:14:55 [ERROR] Error reading master configurationrn120213 14:45:51 [ERROR] Error reading master configurationrn120213 14:46:26 [ERROR] Error reading master configurationrn120213 14:46:33 [ERROR] Error reading master configurationrn120213 14:46:59 [ERROR] Error reading master configurationrn120213 14:47:47 [ERROR] Failed to open log (file './localhost-relay-bin.000018', errno 2)rn120213 14:47:47 [ERROR] Failed to open the relay log 'FIRST' (relay_log_pos 4)rn120213 14:47:47 [ERROR] Could not open log filern120213 14:48:23 [ERROR] Error reading master configurationrn120213 14:48:45 [ERROR] Error reading master configurationrn120213 14:56:14 [ERROR] Error reading master configurationrnrnrn这是日志 现在 start slave 也报错! 这个该怎么解决? 论坛

没有更多推荐了,返回首页