主库binlog被purge的情形
1.演示实验环境
--主库版本:
root@(none)>show variables like 'version';
+---------------+---------------------+
| Variable_name | Value |
+---------------+---------------------+
| version | 5.7.23-23-31.31-log |
+---------------+---------------------+
1 row in set (0.01 sec) --复制模式
root@(none)>show variables like '%gtid_mode%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| gtid_mode | ON |
+---------------+-------+
1 row in set (0.00 sec) --复制进程
root@(none)>show processlist;
+----+-----------------+---------------------+-------+------------------+-------+---------------------------------------------------------------+------------------+-----------+---------------+
| Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined |
+----+-----------------+---------------------+-------+------------------+-------+---------------------------------------------------------------+------------------+-----------+---------------+
| 1 | event_scheduler | localhost | NULL | Daemon | 14232 | Waiting on empty queue | NULL | 0 | 0 |
| 9 | repl | 192.168.2.101:53422 | NULL | Binlog Dump GTID | 11941 | Master has sent all binlog to slave; waiting for more updates | NULL | 0 | 0 |
| 14 | root | localhost | NULL | Query | 0 | starting | show processlist | 0 | 0 |
+----+-----------------+---------------------+-------+------------------+-------+---------------------------------------------------------------+------------------+-----------+---------------+
8 rows in set (0.00 sec) root@(none)> --从库状态
root@(none)>show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.100
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000014
Read_Master_Log_Pos: 194
Relay_Log_File: relay-bin.000005
Relay_Log_Pos: 407
Relay_Master_Log_File: mysql-bin.000014
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: 194
Relay_Log_Space: 695
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: 015d4d11-0363-11e9-bb6c-0800279a3030
Master_Info_File: /mysql/3306/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: 015d4d11-0363-11e9-bb6c-0800279a3030:1-4
Executed_Gtid_Set: 015d4d11-0363-11e9-bb6c-0800279a3030:1-4
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
root@(none)> 2.主库binlog被purge的情形
--停止从库,模拟从库宕机状态
root@pxc01>stop slave;
Query OK, 0 rows affected (0.02 sec) root@pxc01>show slave status \G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.2.100
Master_User: repl
Master_Port: 3306
............
Slave_IO_Running: No
Slave_SQL_Running: No --此时主库上的gtid_purged为空
root@(none)>show variables like '%gtid_purged%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| gtid_purged | |
+---------------+-------+
1 row in set (0.01 sec) root@(none)> --查看主库binlog
root@pxc01>show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000009 | 154 |
| mysql-bin.000010 | 635 |
| mysql-bin.000011 | 201 |
| mysql-bin.000012 | 177 |
| mysql-bin.000013 | 1087 |
| mysql-bin.000014 | 706 |
+------------------+-----------+ --查看测试数据
root@pxc01>select * from tbx;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec) root@pxc01> --从主库删除记录
root@pxc01>delete from tbx;
Query OK, 3 rows affected (0.09 sec) root@pxc01> --切换日志
root@pxc01>flush logs;
Query OK, 0 rows affected (0.08 sec) root@pxc01> --新增记录
root@pxc01>insert into tbx values(4);
root@pxc01>insert into tbx values(5);
root@pxc01>insert into tbx values(6); --查看主库binlog
root@pxc01>show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000009 | 154 |
| mysql-bin.000010 | 635 |
| mysql-bin.000011 | 201 |
| mysql-bin.000012 | 177 |
| mysql-bin.000013 | 1087 |
| mysql-bin.000014 | 1019 |
| mysql-bin.000015 | 962 |
+------------------+-----------+ --清理binlog
root@pxc01>purge binary logs to 'mysql-bin.000015';
Query OK, 0 rows affected (0.08 sec) root@pxc01>show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000015 | 962 |
+------------------+-----------+
1 row in set (0.00 sec) root@pxc01> --此时可以看到相应的gtid_purged值
root@pxc01>show variables like '%gtid_purged%';
+---------------+------------------------------------------+
| Variable_name | Value |
+---------------+------------------------------------------+
| gtid_purged | 015d4d11-0363-11e9-bb6c-0800279a3030:1-7 |
+---------------+------------------------------------------+
1 row in set (0.01 sec) root@pxc01> --下面启动从库
root@(none)>start slave;
Query OK, 0 rows affected (0.06 sec) root@(none)>show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Slave_IO_Running: No
Slave_SQL_Running: Yes
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.'
Retrieved_Gtid_Set: 015d4d11-0363-11e9-bb6c-0800279a3030:1-6
Executed_Gtid_Set: 015d4d11-0363-11e9-bb6c-0800279a3030:1-6
Auto_Position: 1 -- 从库上gtid_purged参数,此时为空
root@(none)>show variables like '%gtid_purged%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| gtid_purged | |
+---------------+-------+
1 row in set (0.01 sec) root@(none)> --停止从库
root@(none)>stop slave; --下面尝试使用gtid_purged进行跳过事务。
root@(none)>set global gtid_purged = '015d4d11-0363-11e9-bb6c-0800279a3030:1-7';
ERROR 1840 (HY000): @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty.
root@(none)>
提示:仅仅当GLOBAL.GTID_EXECUTED为空才能被设置 --查看从库当前的gtid_executed。gtid_executed肯定是不为空,且这些gtid记录在从库的binary log中
root@(none)>show global variables like '%gtid_executed%'\G
*************************** 1. row ***************************
Variable_name: gtid_executed
Value: 015d4d11-0363-11e9-bb6c-0800279a3030:1-6
*************************** 2. row ***************************
Variable_name: gtid_executed_compression_period
Value: 1000
2 rows in set (0.01 sec) root@(none)> --下面我们在从库上reset master,即清空从库binlog
root@(none)>reset master;
Query OK, 0 rows affected (0.10 sec) --再次查看gtid_executed已经为空值
root@(none)>show global variables like '%gtid_executed%'\G
*************************** 1. row ***************************
Variable_name: gtid_executed
Value:
*************************** 2. row ***************************
Variable_name: gtid_executed_compression_period
Value: 1000
2 rows in set (0.01 sec) root@(none)> --此时再次设置gtid_purged的值
root@(none)>set global gtid_purged = '015d4d11-0363-11e9-bb6c-0800279a3030:1-7';
Query OK, 0 rows affected (0.06 sec) --启动从库
root@(none)>start slave;
root@(none)>show slave status \G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.100
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000015
Read_Master_Log_Pos: 962
Relay_Log_File: relay-bin.000006
Relay_Log_Pos: 1175
Relay_Master_Log_File: mysql-bin.000015
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: 962
Relay_Log_Space: 2141
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: 015d4d11-0363-11e9-bb6c-0800279a3030
Master_Info_File: /mysql/3306/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: 015d4d11-0363-11e9-bb6c-0800279a3030:1-6:8-10
Executed_Gtid_Set: 015d4d11-0363-11e9-bb6c-0800279a3030:1-10
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec) 注当前主从记录是不一致的:前期在主库delete的事务未传到从库,需要手动删除!
主库记录:
root@pxc01>select * from tbx;
+------+
| id |
+------+
| 4 |
| 5 |
| 6 |
+------+
3 rows in set (0.00 sec) root@pxc01> 从库记录:
root@pxc01>select * from tbx;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
+------+
6 rows in
主库binlog被purge的情形的更多相关文章
- 主库binlog(master-log)与从库relay-log的关系
主库binlog: # at # :: server id end_log_pos CRC32 COMMIT/*!*/; # at # :: server id end_log_pos CRC32 e ...
- Mysql设置主库binlog文件自动清理
mysql主库中设置了打开binlog模式后,会在datadir目录下生成大量的日志文件,mysql默认是不会自动清理的,我们来设置下mysql自动清理binlog文件 一.打开mysql [root ...
- 使用mysqlbinlog对主库binlog进行同步
#!/bin/bash BASEDIR="/usr/local/mysql" BIN="$BASEDIR/bin" MYSQLBINLOG="$BIN ...
- gtid error set test
1.从库报主键重复(Errno: 1062)#create test data 1062create table t1 (id tinyint not null primary key,ename v ...
- MySQL GTID 错误处理汇总
MySQL GTID是在传统的mysql主从复制的基础之上演化而来的产物,即通过UUID加上事务ID的方式来确保每一个事物的唯一性.这样的操作方式使得我们不再需要关心所谓的log_file和log_P ...
- MySQL 常见面试知识点
之前简单总结了一下MySQL的场景面试知识点 1.讲下MVCC原理 2.MySQL高可用架构介绍 3.OSC(在线更改表结构)原理 4.MySQL性能调优有哪些关键点/经验 5.MySQL在线备份方案 ...
- binlog——逻辑复制的基础
Ⅰ.binlog定义和作用 1.1 定义 记录每次数据库的逻辑操作(包括表结构变更和表数据修改) 包含:binlog文件和index文件 1.2 作用 复制:从库读取主库binlog,本地回放实现复制 ...
- 正确清理binlog日志
摘要: MySQL中的binlog日志记录了数据库中数据的变动,便于对数据的基于时间点和基于位置的恢复,但是binlog也会日渐增大,占用很大的磁盘空间,因此,要对binlog使用正确安全的方法清理掉 ...
- 【MySQL】MySQL主从库配置和主库宕机解决方案
1.转载:https://blog.csdn.net/zfl589778/article/details/51441719/ 2.效果:亲测有效,数据写入成功. 3.主机宕机后,如果不是长时间宕机,且 ...
随机推荐
- 修复jqgrid setgridparam postdata 的多次查询条件累加
//根据elements查询出的参数个数的不同,而传递不同个数的查询参数 start var elements = node.attributes.text.split(","); ...
- C# 单例模式(Singleton)
摘要 在我们日常的工作中经常需要在应用程序中保持一个唯一的实例,如:IO处理,数据库操作等,由于这些对象都要占用重要的系统资源,所以我们必须限制这些实例的创建或始终使用一个公用的实例,这就是我们今天要 ...
- 深入理解java虚拟机(四)垃圾收集算法及HotSpot实现
垃圾收集算法 一般来说,垃圾收集算法分为四类: 标记-清除算法 最基础的算法便是标记-清除算法(Mark-Sweep).算法分为“标记”和“清除”两个阶段:首先标记处需要收集的对象,在标记完成之后,再 ...
- linux 分区 文件系统
操作系统通过文件系统管理文件及数据,磁盘或分区需要创建文件系统之后才能为操作系统使用,创建文件系统的过程又称之为格式化. 没有文件系统的设备称之为裸设备(raw); 常见的文件系统有fat32,NTF ...
- 从Entity Framework的实现方式来看DDD中的repository仓储模式运用
一:最普通的数据库操作 static void Main(string[] args) { using (SchoolDBEntities db = new SchoolDBEntities()) { ...
- 自定义spring valid方式实现验证
推荐:http://blog.csdn.net/xulianboblog/article/details/51694924
- C#线程/进程同步(lock、Mutex、Semaphore)
一.lock(实质是Monitor.Enter和Monitor.Exit)(线程同步) 二.Mutex(互斥量)(线程/进程同步) Mutex有个好的特性是,如果程序结束时而互斥锁没通过Release ...
- ref 和 out 的用法和区别以及params用法
方法参数可以划分为一下四种类型1 值参数:声明时不含任何修饰符2 引用参数:以ref修饰符声明3 输出参数:以out修饰符声明4 参数数组:以params修饰符声明 引用参数和输出参数不创建新的存储位 ...
- .net core i上 K8S(三)Yaml文件运行.netcore程序
上一章我们通过kubectl run简单运行了一个.netcore网站,但实际的开发中,我们都是通过yaml来实现的. 1.编写yaml文件 关于yaml文件的格式在此就不多描述了,不熟悉的可以去网上 ...
- 2、ASP .NETCore 2.0之视图
一.Razor基础 声明:Razor不是编程语言,是服务器端标记语言.Razor是一种允许开发者在网页中嵌入服务器端代码的标记语法(主要是针对VB和C#). 1.C#中Razor基本语法 (1).Ra ...