mysql gtid坑_通过mysqlbinlog --skip-gtids恢复后再备份可能造成的坑

版本

[root@uz22199 backup]# innobackupex --version

innobackupex version 2.4.8 Linux (x86_64) (revision id: 97330f7)

[root@uz22199 backup]# mysql -e"select @@version"

+------------+

| @@version |

+------------+

| 5.7.18-log |

+------------+

源库

表结构与数据

root@mysqldb 21:51: [fandb]> show create table users\G

***************************1. row ***************************

Table: users

Create Table: CREATE TABLE `users` (

`email` varchar(10) DEFAULT NULL,

UNIQUE KEY `email` (`email`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

1 row in set (0.00 sec)

root@mysqldb 18:43: [fandb]> select* from users;

+-------+

| email | +-------+

| 1 |

| 10 |

| 20 |

| 30 |

| 5 | +-------+

插入一条数据

insert into users values(50); --GTID=1297

再删掉

delete from users where email=50; ----GTID=1298

当前Executed_Gtid_Set

root@mysqldb 18:35: [fandb]> show master status;

+------------------+----------+--------------+------------------+---------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+---------------------------------------------+

| mysql-bin.000005 | 495 | | | 5c351518-78ec-11e7-8e7a-005056a610c3:1-1298 | +------------------+----------+--------------+------------------+---------------------------------------------+

1 row in set (0.00 sec)

源库再次应用一下已经执行过得binlog, 再次应用insert into users values(50); 这一条

这里先不考虑有没有可能这样子去恢复数据,只做实验

[root@test43100 backup]# mysqlbinlog --skip-gtids --include-gtids='5c351518-78ec-11e7-8e7a-005056a610c3:1297' mysql-bin.000005 |mysql

root@mysqldb 18:43: [fandb]> select* from users;

+-------+

| email | +-------+

| 1 |

| 10 |

| 20 |

| 30 |

| 5 |

| 50 | +-------+

root@mysqldb 18:43: [fandb]> show master status;

+------------------+----------+--------------+------------------+---------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+---------------------------------------------+

| mysql-bin.000005 | 617 | | | 5c351518-78ec-11e7-8e7a-005056a610c3:1-1299 | +------------------+----------+--------------+------------------+---------------------------------------------+

源库Executed_Gtid_Set 已经到1299了

备份

innobackupex --user=backup --password='backup' --stream=tar /tmp | gzip -> full.tar.gz

170907 18:45:15 Backup created in directory '/tmp/'

MySQL binlog position: filename 'mysql-bin.000005', position '617', GTID of the last change '5c351518-78ec-11e7-8e7a-005056a610c3:1-1299'

170907 18:45:15 [00] Streaming

170907 18:45:15 [00] ...done

170907 18:45:15 [00] Streaming

170907 18:45:15 [00] ...done

xtrabackup: Transaction log of lsn (3112759) to (3112768) was copied.

170907 18:45:16 completed OK!

从备份输出信息和xtrabackup_binlog_info都可以看到,这个全备备份了1-1299

[root@uz22199 full2]# more xtrabackup_binlog_info

mysql-bin.000005 617 5c351518-78ec-11e7-8e7a-005056a610c3:1-1299

把备份随便搞到一个地方恢复出来

(恢复过程省略)

查看恢复出来的库的Executed_Gtid_Set

root@mysqldb 18:48: [(none)]> show master status;

+------------------+----------+--------------+------------------+---------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+---------------------------------------------+

| mysql-bin.000001 | 154 | | | 5c351518-78ec-11e7-8e7a-005056a610c3:1-1298 | +------------------+----------+--------------+------------------+---------------------------------------------+

1 row in set (0.00 sec)

虽然知道1298,但是50这条数据有了

root@mysqldb 18:43: [fandb]> select* from users;

+-------+

| email | +-------+

| 1 |

| 10 |

| 20 |

| 30 |

| 5 |

| 50 | +-------+

如果此时我们直接将该库作为从库,change master到源库,那么start slave会报错,1299会再执行一边insert 50,会报1062错误.这就是坑

而如果我们flush binary logs一次,再做全备

root@mysqldb 21:51: [fandb]> flush binary logs;

Query OK, 0 rows affected (0.19 sec)

root@mysqldb 21:59: [fandb]> show master status;

+------------------+----------+--------------+------------------+---------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+---------------------------------------------+

| mysql-bin.000006 | 194 | | | 5c351518-78ec-11e7-8e7a-005056a610c3:1-1299 | +------------------+----------+--------------+------------------+---------------------------------------------+

1 row in set (0.00 sec)

170907 22:00:58 Backup created in directory '/tmp/'

MySQL binlog position: filename 'mysql-bin.000006', position '194', GTID of the last change '5c351518-78ec-11e7-8e7a-005056a610c3:1-1299'

170907 22:00:58 [00] Streaming

170907 22:00:58 [00] ...done

170907 22:00:58 [00] Streaming

170907 22:00:58 [00] ...done

xtrabackup: Transaction log of lsn (3115326) to (3115335) was copied.

170907 22:00:58 completed OK!

[root@uz22199 full3]# more xtrabackup_binlog_info

mysql-bin.000006 194 5c351518-78ec-11e7-8e7a-005056a610c3:1-1299

Executed_Gtid_Set依旧是1-1299

再次将备份恢复出来,查看新恢复出来的库

root@mysqldb 22:02: [(none)]> show master status;

+------------------+----------+--------------+------------------+---------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+---------------------------------------------+

| mysql-bin.000001 | 154 | | | 5c351518-78ec-11e7-8e7a-005056a610c3:1-1299 | +------------------+----------+--------------+------------------+---------------------------------------------+

此时恢复出来的库Executed_Gtid_Set为1-1299了

总结

那么要么以后通过mysqlbinlog –skip-gtids 恢复数据之后flush 一下binary logs;

要么恢复出来的库都手动根据xtrabackup_binlog_info去set global gtid_purged

又做了一次

源库:

root@mysqldb 17:14: [(none)]> flush binary logs;

Query OK, 0 rows affected (0.24 sec)

root@mysqldb 17:16: [(none)]> show master status;

+------------------+----------+--------------+------------------+---------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+---------------------------------------------+

| mysql-bin.000008 | 194 | | | 5c351518-78ec-11e7-8e7a-005056a610c3:1-1300 | +------------------+----------+--------------+------------------+---------------------------------------------+

root@mysqldb 17:17: [(none)]> select * from fandb.users order by 1;

+-------+

| email | +-------+

| 1 |

| 10 |

| 20 |

| 30 |

| 5 |

| 50 |

| 60 | +-------+

7 rows in set (0.00 sec)

root@mysqldb 17:23: [(none)]> insert into fandb.users values(70);

Query OK, 1 row affected (0.06 sec)

root@mysqldb 17:23: [(none)]> show master status;

+------------------+----------+--------------+------------------+---------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+---------------------------------------------+

| mysql-bin.000008 | 448 | | | 5c351518-78ec-11e7-8e7a-005056a610c3:1-1301 | +------------------+----------+--------------+------------------+---------------------------------------------+

1 row in set (0.00 sec)

root@mysqldb 17:24: [(none)]> delete from fandb.users where email=70;

Query OK, 1 row affected (0.05 sec)

root@mysqldb 17:24: [(none)]> show master status;

+------------------+----------+--------------+------------------+---------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+---------------------------------------------+

| mysql-bin.000008 | 702 | | | 5c351518-78ec-11e7-8e7a-005056a610c3:1-1302 | +------------------+----------+--------------+------------------+---------------------------------------------+

1 row in set (0.00 sec)

root@mysqldb 17:24: [(none)]> select * from fandb.users order by 1;

+-------+

| email | +-------+

| 1 |

| 10 |

| 20 |

| 30 |

| 5 |

| 50 |

| 60 | +-------+

7 rows in set (0.00 sec)

mysqlbinlog --skip-gtids --include-gtids='5c351518-78ec-11e7-8e7a-005056a610c3:1301' /data/mysqldata/3306/binlog/mysql-bin.000008 |mysql

root@mysqldb 17:26: [(none)]> show master status;

+------------------+----------+--------------+------------------+---------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+---------------------------------------------+

| mysql-bin.000008 | 956 | | | 5c351518-78ec-11e7-8e7a-005056a610c3:1-1303 | +------------------+----------+--------------+------------------+---------------------------------------------+

1 row in set (0.00 sec)

root@mysqldb 17:26: [(none)]> select * from fandb.users order by 1;

+-------+

| email | +-------+

| 1 |

| 10 |

| 20 |

| 30 |

| 5 |

| 50 |

| 60 |

| 70 | +-------+

8 rows in set (0.00 sec)

innobackupex --user=backup --password='backup' --stream=tar /tmp | gzip -> full4.tar.gz

MySQL binlog position: filename 'mysql-bin.000008', position '956', GTID of the last change '5c351518-78ec-11e7-8e7a-005056a610c3:1-1303'

170908 17:27:42 [00] Streaming

170908 17:27:42 [00] ...done

170908 17:27:42 [00] Streaming

170908 17:27:42 [00] ...done

xtrabackup: Transaction log of lsn (3121237) to (3121246) was copied.

170908 17:27:42 completed OK!

[root@uz22199 full4]# more xtrabackup_binlog_info

mysql-bin.000008 956 5c351518-78ec-11e7-8e7a-005056a610c3:1-1303

[root@uz22199 full4]# more xtrabackup_binlog_pos_innodb mysql-bin.000008 956

恢复出来的库:

root@mysqldb 17:31: [(none)]> show master status;

+------------------+----------+--------------+------------------+---------------------------------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+---------------------------------------------+

| mysql-bin.000001 | 154 | | | 5c351518-78ec-11e7-8e7a-005056a610c3:1-1300 | +------------------+----------+--------------+------------------+---------------------------------------------+

1 row in set (0.00 sec)

root@mysqldb 17:31: [(none)]> select * from fandb.users;

+-------+

| email | +-------+

| 1 |

| 10 |

| 20 |

| 30 |

| 5 |

| 50 |

| 60 |

| 70 | +-------+

8 rows in set (0.00 sec)

root@mysqldb 17:37: [(none)]> reset slave all;

Query OK, 0 rows affected (0.03 sec)

root@mysqldb 17:38: [(none)]> change master to master_host='10.4.3.100',master_port=3306,master_user='repl',master_password='repl',master_auto_position=1;

Query OK, 0 rows affected, 2 warnings (0.26 sec)

root@mysqldb 17:38: [(none)]> start slave;

Last_SQL_Error: Could not execute Write_rows event on table fandb.users; Duplicate entry '70' for key 'email', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.000008, end_log_pos 417

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/398180.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SqlHelper模板

在实际开发中,我们不会直接使用拼写SQL语句的方法进行数据库操作,而是使用参数化的方法进行数据库操作,这样做的好处很多,不仅提高了程序的健壮性,同时也避免的SQL注入的问题。在这里,笔者为初学者提供一个…

164. Maximum Gap

题目:Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Try to solve it in linear time/space. Return 0 if the array contains less than 2 elements. You may assume all elements in the array are…

java声明和初始化数组_Java 中初始化数组

数组是一种有用的数据类型,用于管理在连续内存位置中建模最好的集合元素。下面是如何有效地使用它们。-- Chris Hermansen(作者)有使用 C 或者 FORTRAN 语言编程经验的人会对数组的概念很熟悉。它们基本上是一个连续的内存块,其中…

Java第二次实验报告——Java面向对象程序设计

北京电子科技学院(BESTI)实 验 报 告课程名称:java程序设计实验 班级:1352 姓名:洪韶武 学号:20135219成绩: 指导教师:娄嘉鹏…

IOS 多线程04-GCD详解 底层并发 API

IOS 多线程04-GCD详解 底层并发 API 注:本人是翻译过来,并且加上本人的一点见解。 前言 想要揭示出表面之下深层次的一些可利用的方面。这些底层的 API 提供了大量的灵活性,随之而来的是大量的复杂度和更多的责任。在我们的文章常见的后台实践…

类初始化的一道面试题

下面的代码counter1,counter2输出的结果是什么,把第10行放到12行后面,ounter1,counter2输出的结果是什么? 为什么? 1 public class Test {2 public static void main(String[] args) {3 System.out.println(Singleton…

mac pandas文件路径_Mac进阶必看:如何利用Automator快速获取文件路径

在重装mac os系统后,有的小伙伴会选择手动恢复数据,但是却发现一些软件比如FTP、iterm2、foxmail等这些软件的配置信息没有了,其实数据并没有丢失哦!一般情形下数据都会在/Users/dcm/Library下,但是Mac默认是不显示这些…

深入分析Spring 与 Spring MVC容器

spring官方文档中对web容器的说明spring配置文件默认名字——applicationContext.xml参考链接:https://www.cnblogs.com/hujunzheng/p/5673377.htmlSpring的启动过程:首先,对于一个web应用,其部署在web容器中,web容器提…

mysql jpa 批注 视图_通过JPA注解映射视图的实体类 jpa 视图 无主键 @Query注解的用法(Spring Data JPA) jpa 使用sql语句...

参考: https://blog.csdn.net/qq465235530/article/details/68064074https://www.cnblogs.com/zj0208/p/6008627.html这里主要说一下怎么用jpa映射一个视图的实体类,其实跟表映射一样,就是需要添加一个空的主键id标识package com.cf.bus.core.rs.templat…

笨办法学C 练习45:一个简单的TCP/IP客户端

练习45:一个简单的TCP/IP客户端 原文:Exercise 45: A Simple TCP/IP Client 译者:飞龙 我打算使用RingBuffer来创建一个非常简单的小型网络测试工具,叫做netclient。为此我需要向Makefile添加一些工具,来处理bin/目录下…

Cppunit 源码 SynchronizedObject

运用C的构造&#xff0c;析构进行&#xff0c;加锁解锁。在函数进入的时候定义临时变量。任何一个分支推出的时候都会调用析构函数。避免多分支出现的问题。 1 #ifndef CPPUNIT_SYNCHRONIZEDOBJECT_H2 #define CPPUNIT_SYNCHRONIZEDOBJECT_H3 4 #include <cppunit/Portabil…

hive安装需要安装mysql区别_HIVE安装系列之一:在Linux中安装mysql,为其作为hive的metastore做准备...

安装mysql的Linux机器是Centos6的系统&#xff0c;机器名字叫combanc05mysql我采用的是5.5版本。安装过程中需要解决新旧版的冲突问题&#xff0c;并允许mysql被远程访问。以便其作为hive的元数据仓库顺利运行。下载到mysql在linux中安装mysql&#xff0c;首先可以到官网去找Li…

数据预处理和特征工程

一、数据预处理 1.数据采集 2.数据格式化&#xff08;存储格式等&#xff09; 3.数据清洗&#xff1a;去掉脏数据 简单直观可以看出的不可能数据 组合或统计属性判定 缺失值处理 1.删除元祖&#xff1a;删除这一条记录或者一列特征&#xff0c;适合记录或者特征占总样本比例很小…

个人作业五:四则运算二

四则运算2 一、设计思路&#xff1a; 1、题目避免重复&#xff1a; (1)利用系统时间来产生随机数&#xff0c;重复率会降低。 (2)建立链表&#xff0c;逐个判断。可读取写入文件。 2、可定制&#xff08;数量/打印方式&#xff09;&#xff1a; (1)格式有默认值; (2)可以选择重…

javascript继承模式原理与示例深入剖析

原型链ECMAScript 中描述了原型链的概念&#xff0c;并将原型链作为实现继承的主要方法。 其基本思想是利用原型让一个引用类型继承另一个引用类型的属性和方法。简单回顾一下构造函数、原型和实例的关系&#xff1a;每个构造函数都有一个原型对象&#xff0c;原型对象都包含一…

mysql innodb_sort_buffer_size_mysql优化---第7篇:参数 innodb_buffer_pool_instances设置

摘要&#xff1a;1 innodb_buffer_pool_instances可以开启多个内存缓冲池&#xff0c;把需要缓冲的数据hash到不同的缓冲池中&#xff0c;这样可以并行的内存读写。2 innodb_buffer_pool_instances参数显著的影响测试结果&#xff0c;特别是非常高的 I/O 负载时。3 实验环境下&…

函数和过程

函数&#xff1a;def test(s)&#xff1a; ... return 过程没有return&#xff0c;函数有。但是过程也是函数 def test0():过程msgi am houndprint(msg) def test1():函数msgi am dogprint(msg)return msg t1test0() t2test1() print(t1) print(t2) i am houndi am dogNone 没…

关于html的一些杂技

html预定义字符指的是 :< > html实体指的是 $amp 等 php中htmlspeciachar()就是讲html预定义字符转换成html实体. 浏览器渲染时,会将html实体转换成html预定义字符显示出来,但是查看html源码是显示的还是html实体. 而如果查看源码时(ctrlu),中<>的内容不会再网页…

cordova 5.0版本说明

2015/04/21发布Cordova 5.0.0! 1&#xff09;插件从Cordova plugins registry&#xff08;CPR&#xff09;全部移到npm&#xff0c;并且重新命名 ***org.apache.cordova.* → cordova-plugin-* 旧&#xff09;$ cordova plugin add org.apache.cordova.console 新&#xff09…

mysql综合查询索引优化_MySQL数据库SQL优化之确定问题使用索引提高查询效率

在EXPLAIN分析SQL中&#xff0c;已经可以确定是对客户表customet的全表扫描导致效率的不理想&#xff0c;那么对客户表customer的email字段创建索引&#xff0c;具体如下:mysql> create index idx_email on customer(email);创建索引后&#xff0c;再看一下这条语句的执行计…