首页 > 其他分享 >Auto_Position=1 主库清空部分binlog从库错误(1236)的解决办法

Auto_Position=1 主库清空部分binlog从库错误(1236)的解决办法

时间:2023-05-12 14:13:42浏览次数:45  
标签:主库 binlog 1236 Last Log SSL Master Replicate gtid

环境:

OS:Centos 7

DB:mysql 5.7.29

1.从库同步错误如下:

mysql> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 192.168.1.104
                  Master_User: repl
                  Master_Port: 13306
                Connect_Retry: 60
              Master_Log_File: binlog.000010
          Read_Master_Log_Pos: 89768076
               Relay_Log_File: relaylog-binlog.000007
                Relay_Log_Pos: 89768283
        Relay_Master_Log_File: binlog.000010
             Slave_IO_Running: No
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: information_schema,performance_schema,sys
           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: 89768076
              Relay_Log_Space: 89768574
              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: 'The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires. Replicate the missing transactions from elsewhere, or provision a new slave from backup. Consider increasing the master's binary log expiration period. The GTID set sent by the slave is '636915ca-ef98-11ed-a854-080027962264:1-836,
9ecf61e2-eed1-11ed-a4b0-080027e81195:1-457', and the missing transactions are '9ecf61e2-eed1-11ed-a4b0-080027e81195:458-465'.'
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 1
                  Master_UUID: 9ecf61e2-eed1-11ed-a4b0-080027e81195
             Master_Info_File: /opt/mysql57/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 230511 23:11:27
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 9ecf61e2-eed1-11ed-a4b0-080027e81195:358-457
            Executed_Gtid_Set: 636915ca-ef98-11ed-a854-080027962264:1-836,
9ecf61e2-eed1-11ed-a4b0-080027e81195:1-457
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

ERROR: 
No query specified

 

2.重置从库
mysql> stop slave;
mysql> reset slave;##情况错误信,Master_Log_File项
mysql> reset master; ##清空Retrieved_Gtid_Set和Executed_Gtid_Set项

 

3.获取跳过的gtid

主库上获取:

mysql> show variables like '%gtid%';
+----------------------------------+--------------------------------------------+
| Variable_name                    | Value                                      |
+----------------------------------+--------------------------------------------+
| binlog_gtid_simple_recovery      | ON                                         |
| enforce_gtid_consistency         | ON                                         |
| gtid_executed_compression_period | 1000                                       |
| gtid_mode                        | ON                                         |
| gtid_next                        | AUTOMATIC                                  |
| gtid_owned                       |                                            |
| gtid_purged                      | 9ecf61e2-eed1-11ed-a4b0-080027e81195:1-569 |
| session_track_gtids              | OFF                                        |
+----------------------------------+--------------------------------------------+
8 rows in set (0.01 sec)

 

从库上获取

mysql> show variables like '%gtid%';
+----------------------------------+-----------+
| Variable_name                    | Value     |
+----------------------------------+-----------+
| binlog_gtid_simple_recovery      | ON        |
| enforce_gtid_consistency         | ON        |
| gtid_executed_compression_period | 1000      |
| gtid_mode                        | ON        |
| gtid_next                        | AUTOMATIC |
| gtid_owned                       |           |
| gtid_purged                      |           |
| session_track_gtids              | OFF       |
+----------------------------------+-----------+
8 rows in set (0.01 sec)

 

我这里从库上的gtid_purged为空,若有值的话需要加入到如下语句(该语句在从库上执行,多个gtid组以逗号,分隔)

mysql>set @@global.gtid_purged='9ecf61e2-eed1-11ed-a4b0-080027e81195:1-569';

 

查看状态

mysql> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.104
                  Master_User: repl
                  Master_Port: 13306
                Connect_Retry: 60
              Master_Log_File: binlog.000014
          Read_Master_Log_Pos: 73446644
               Relay_Log_File: relaylog-binlog.000006
                Relay_Log_Pos: 73446851
        Relay_Master_Log_File: binlog.000014
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: information_schema,performance_schema,sys
           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: 73446644
              Relay_Log_Space: 73447142
              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: 0
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: 9ecf61e2-eed1-11ed-a4b0-080027e81195
             Master_Info_File: /opt/mysql57/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 9ecf61e2-eed1-11ed-a4b0-080027e81195:570-657 ##这里从570开始接收,因为上面569已经跳过了.
            Executed_Gtid_Set: 9ecf61e2-eed1-11ed-a4b0-080027e81195:1-657
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

ERROR: 
No query specified

 

这种恢复方式只能保证同步正常运行,但是跳过了的事务会导致主从两端的数据不一致。

 

标签:主库,binlog,1236,Last,Log,SSL,Master,Replicate,gtid
From: https://www.cnblogs.com/hxlasky/p/17393939.html

相关文章

  • mysql主从复制(gtid模式)修改主库ip
    环境:OS:Centos7DB:mysql5.7.29 基于GTID复制的主从环境,主库修改了ip后,修改从库同步信息(不需要指定master_log_file和master_log_pos)1.停掉从库stopslave; 2.查看从库状态mysql>showslavestatus\G;***************************1.row*********************......
  • MySQL的redolog和binlog有哪些区别?
    redolog是innodb生成的日志,主要为了保证数据的可靠性;binlog是MySQLserver层面上生成的日志,主要用于pointintime恢复和主从复制。undolog主要用于事务的回滚和一致性快照读(MVCC多版本并发控制)。MySQL中的redolog、binlog的功能很像,那么有什么区别?区别如下:red......
  • MySQL如何获取binlog的开始时间和结束时间
    MySQL数据库恢复到指定时间点时,我们必须通过MySQL全备+MySQL增量备份(可选)+MySQL的二进制日志(binlog)进行重放来恢复到指定时间点,实际的生产环境中,可能一段时间内生成了多个二进制日志文件(binlog),MySQL本身不会存储二进制日志文件(binlog)的开始时间和结束时间,如果要还原到某个时间点......
  • MySQL 8.0关闭binlog
    MySQL8.0关闭binlog默认开启binlog,即使在my.ini或my.cnf的[mysqld]部分没有log_bin或log_bin=mysql-binbinlog默认在Linux的/var/lib/mysql目录下,文件名为binlog.000001格式,在Windows的data目录下,文件名为binlog.000001格式相当于默认有log_bin=binlog参数如果需要关闭......
  • [数据库]MYSQL之授予/查验binlog权限
    在后端做主从备份;亦或是在大数据领域中,各类CDC同步(Canal/FlinkCDC等),均会基于MYSQL的binlog来实现。因此,知道需要哪些权限?怎么查验去、怎么授权就很重要了。感觉网上的文章没成体系地清楚,而今天工作上处理问题的过程中遇到了此疑问,且曾多次对此产生疑问,自然便有了这一篇,作......
  • 解决MySQL数据库同步1236错误
    转载于:https://www.cnblogs.com/dukuan/p/8744295.html1、报错如下:Gotfatalerror1236frommasterwhenreadingdatafrombinarylog:'TheslaveisconnectingusingCHANGEMASTERTOMASTER_AUTO_POSITION=1,butthemasterhaspurgedbinarylogscontaining......
  • 2.mysql binlog的三种格式及区别
    好文:https://www.cnblogs.com/syw20170419/p/16443105.html 1、三种格式:row、statement、mixed2、区别:row格式文件比较大,statement比较小,row格式保存的是一行一行的数据,statement保存的是sql语句,mixed格式介于二者之间,statement容易丢数据,row格式则不会3、statement容易丢......
  • windows mysql binlog 日志内容查看
    打开mysqlbinlog.exe所在目录的命令行,执行mysqlbinlog.exe--base64-output=decode-rows-v"D:\mysql-8.0.27-winx64\data\binlog.000111">mysqlbin.logD:\mysql-8.0.27-winx64\data\binlog.000111 本机binlog文件路径名mysqlbin.log 导出到当前下的文件名 ......
  • Virsh常用命令-v4-20210308_123613
    Virsh常用命令企业云平台产品中心共享知识库Exportedon03/08/2021TableofContentsVirsh是基于libvirt写的一个命令行工具,用来通过Virsh来对虚拟机的生命周期进行管理,以下是常用的一些Virsh命令:1、查看在运行的虚拟机virshlist2、查看创建的所有虚拟机virshlist--all3、启......
  • scn增量备份恢复dataguard从库(出现gap后主库有添加新的数据文件)
    环境:OS:Centos7DB:19.3.0.0 1.正常同步情况下的scn主从是一致的主库查询:SQL>selectSEQUENCE#,FIRST_CHANGE#,NEXT_CHANGE#,APPLIED,STATUSfromv$archived_logtwherename='tnsslavea';SEQUENCE#FIRST_CHANGE#NEXT_CHANGE#APPLIEDSTATUS-----------------......