MySQL主从失败报错误: Got fatal error 1236

一、问题原因及报错误信息

由于MySQL主库意外重启,导致从库无法同步报错如下:

登录从库查看主从同步的错误信息

[root@192-168-7-101 mysql]# vim mysqld-error.log 2018-12-11 12:57:35 1788 [ERROR] Error reading packet from server: Client requested master to start replication from position > file size; the first event 'master-bin.002295' at 1021866995, the last event read from './master-bin.002295' at 4, the last byte read from './master-bin.002295' at 4. (server_errno=1236) 2018-12-11 12:57:35 1788 [ERROR] Slave I/O: 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 'master-bin.002295' at 1021866995, the last event read from './master-bin.002295' at 4, the last byte read from './master-bin.002295' at 4.', Error_code: 1236
[root@192-168-7-101 mysql]# mysql -u root -p
mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 192.168.3.230
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.002295
          Read_Master_Log_Pos: 1021866995
               Relay_Log_File: 192-168-3-236-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: master-bin.002295
             Slave_IO_Running: No
            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: 1021866995
              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 'master-bin.002295' at 1021866995, the last event read from './master-bin.002295' at 4, the last byte read from './master-bin.002295' at 4.'
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
                  Master_UUID: f7c24af7-a54a-11e6-88b4-525400169c04
             Master_Info_File: /Data/work/local/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp: 181211 12:57:35
     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)

二、解决方法

1. 先登录到MySQL主库,搜索后并未找到position的位置

[root@192-168-7-100 mysql]# mysqlbinlog --no-defaults --start-position=1021866995 master-bin.002295 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #181210 22:41:27 server id 1 end_log_pos 120 CRC32 0x1fe77f51 Start: binlog v 4, server v 5.6.30-log created 181210 22:41:27 BINLOG ' F3sOXA8BAAAAdAAAAHgAAAAAAAQANS42LjMwLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAXAAEGggAAAAICAgCAAAACgoKGRkAAVF/ 5x8= '/*!*/; DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
2. 解析binlog日志文件,找到离1021866995最近的position最近的位置102186424
[root@
192-168-7-100 mysql]# mysqlbinlog --no-defaults master-bin.002295 >/root/test.sql
[root@192-168-7-100 mysql]# vim /root/test.sql # at
102186284 #181211 0:05:07 server id 1 end_log_pos 102186315 CRC32 0xd5613884 Xid = 1912388 COMMIT/*!*/; # at 102186315 #181211 0:05:07 server id 1 end_log_pos 102186392 CRC32 0x2b89095e Query thread_id=13545 exec_time=1 error_code=0 SET TIMESTAMP=1544457907/*!*/; BEGIN /*!*/; # at 102186392 # at 102186424 3.登录从库,重新指定主从的同步位置
[root@192-168-7-101 mysql]# mysql -u root -p mysql
> stop slave; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> change master to master_log_file='master-bin.002295',master_log_pos=102186424; Query OK, 0 rows affected (0.16 sec) mysql> start slave; Query OK, 0 rows affected (0.03 sec) mysql> show slave status \G *************************** 1. row *************************** Slave_IO_State: Queueing master event to the relay log Master_Host: 192.168.3.230 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.002295 Read_Master_Log_Pos: 155577520 Relay_Log_File: 192-168-7.100-relay-bin.000002 Relay_Log_Pos: 498191 Relay_Master_Log_File: master-bin.002295 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: 102684331 Relay_Log_Space: 53391561 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: 46929 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: 1 Master_UUID: f7c24af7-a54a-11e6-88b4-525400169c04 Master_Info_File: /Data/work/local/mysql/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: updating 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)

猜你喜欢

转载自www.cnblogs.com/cyleon/p/10101787.html
今日推荐