Auto_Position=1 主库清空部分binlog从库错误(1236)的解决办法
环境:
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
这种恢复方式只能保证同步正常运行,但是跳过了的事务会导致主从两端的数据不一致。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2020-05-12 打补丁p19023822_112040_Linux-x86-64