MySQL M-S GTID

基于GTIDs的MySQL Replication

什么是GTIDs以及有什么特定?

1、GTIDs(Global transaction identifiers)全局事务标识符,是mysql 5.6新加入的一项技术

2、当使用GTIDs时,每一个事务都可以被识别并且跟踪

3、添加新的slave或者当发生故障需要将master身份或者角色迁移到slave上时,都无需考虑是哪一个二进制日志以及哪个position值,极大简化了相关操作

4、GTIDs是完全基于事务的,因此不支持MYISAM存储引擎

5、GTID由source_id和transaction_id组成:
1>source_id来自于server_uuid,可以在auto.cnf中看到
2>transation_id是一个序列数字,自动生成

使用GTIDs的限制条件有哪些?

1、不支持非事务引擎(MYisam),因为可能会导致多个gtid分配给同一个事务
2、create table ... select 语句不支持(主库语法报错)
3、create/drop temporary table 语句不支持
4、必须使用enforce-gtid-consistency参数
5、sql-slave-skip-counter不支持(传统的跳过错误方式)
6、GTID复制环境中必须要求统一开启和GTID或者关闭GTID
7、在mysql 5.6.7之前,使用mysql_upgrade命令会出现问题

GTID的生命周期包含以下部分:

1. A transaction is executed and committed on the master.
This transaction is assigned a GTID using the master's UUID and the smallest nonzero transaction sequence number not yet used on this server; the GTID is written to the master's binary log (immediately preceding the transaction itself in the log).

2. After the binary log data is transmitted to the slave and stored in the slave's relay log, the slave reads the GTID and sets the value of its gtid_next system variable as this GTID. This tells the slave that the next transaction must be logged using this GTID.It is important to note that the slave sets gtid_next in a session context.

3. The slave verifies that this GTID has not already been used to log a transaction in its own binary log. If this GTID has not been used, the slave then writes the GTID, applies the transaction, and writes the transaction to its binary log. By reading and checking the transaction's GTID first, before processing the transaction itself, the slave guarantees not only that no previous transaction having this GTID has been applied on the slave, but also that no other session has already read this GTID but has not yet committed the associated transaction. In other words, multiple clients are not permitted to apply the same transaction concurrently.

4. Because gtid_next is not empty, the slave does not attempt to generate a GTID for this transaction but instead writes the GTID stored in this variable—that is, the GTID obtained from the master—immediately preceding the transaction in its binary log.

总结:有了GTID大大的简化了复制的过程,降低了维护的难度

配置基于GTIDs的Replication

在生产环境中,大多数情况下使用的MySQL5.6基本上都是从5.5或者更低的版本升级而来,这就意味着之前的mysql replication方案是基于传统的方式部署,并且已经在运行,因此,接下来我们就利用已有的环境升级至基于GITDs的Replication

传统的方案部署参考:https://www.cnblogs.com/yanjieli/p/9831084.html

注意:

1、开启GITDs需要在master和slave上都配置gtid-mode,log-bin,log-slave-updates,enforce-gtid-consistency(该参数在5.6.9之前是--disable-gtid-unsafe-statement)

2、其次,slave还需要增加skip-slave-start参数,目的是启动的时候,先不要把slave起来,需要做一些配置

详细操作步骤:

当前环境是传统的AB复制转换成GTID模式

master:192.168.1.166

slave:192.168.1.114

1、将master和slave服务器都设置为read-only

mysql>set @@global.read_only=ON;

2、停止两台服务器的mysql服务

3、配置master

master:
[root@master ~]# vim /etc/my.cnf
log-bin=mysql-bin
gtid-mode=on
log-slave-updates
enforce-gtid-consistency
[root@master ~]# service mysqld restart

4、配置slave

slave:
[root@slave1 ~]# vim /etc/my.cnf
gtid-mode=on
log-bin
log-slave-updates
enforce-gtid-consistency
skip-slave-start [root@slave1 ~]# service mysqld restart mysql> change master to master_host='192.168.1.166',master_port=3306,master_user='slave',master_password='',master_auto_position=1; mysql> start slave; mysql> show slave status \G;
Auto_Position: 1

5、关闭read-only模式

mysql> set @@global.read_only=OFF;

6、测试

master查看:
mysql> select * from db01.table03;
+------+------+
| id | name |
+------+------+
| 1 | haha |
| 2 | wowo |
| 4 | yoyo |
| 1 | haha |
| 2 | wowo |
| 4 | yoyo |
+------+------+
6 rows in set (0.07 sec) slave查看:
mysql> select * from db01.table03;
+------+------+
| id | name |
+------+------+
| 1 | haha |
| 2 | wowo |
| 4 | yoyo |
| 1 | haha |
| 2 | wowo |
| 4 | yoyo |
+------+------+
6 rows in set (0.07 sec) master插入数据并查看:
mysql> insert into db01.table03 values(5,'ouou');
Query OK, 1 row affected (0.04 sec) mysql> select * from db01.table03;
+------+------+
| id | name |
+------+------+
| 1 | haha |
| 2 | wowo |
| 4 | yoyo |
| 1 | haha |
| 2 | wowo |
| 4 | yoyo |
| 5 | ouou |
+------+------+
7 rows in set (0.00 sec) slave查看:
mysql> select * from db01.table03;
+------+------+
| id | name |
+------+------+
| 1 | haha |
| 2 | wowo |
| 4 | yoyo |
| 1 | haha |
| 2 | wowo |
| 4 | yoyo |
| 5 | ouou |
+------+------+
7 rows in set (0.00 sec) 并且master上面操作后查看slave的状态,下面就会有事务产生
mysql> show slave status\G;
Retrieved_Gtid_Set: 5624c184-5b55-11e8-b117-000c293dfd08:1
Executed_Gtid_Set: 5624c184-5b55-11e8-b117-000c293dfd08:1
Auto_Position: 1

MySQL基于GTIDs的MySQL Replication的更多相关文章

  1. mysql基于GTIDS复制

    GTIDS的环境:一台master 192.168.200.111多个slave: 192.168.200.112 192.168.200.113 修改master服务器:[root@localhos ...

  2. Mysql基于GTIDs的复制

    通过GTIDs[global transaction identifiers],可以标识每一个事务,并且可以在其一旦提交追踪并应用于任何一个Slave上:这样 就不需要像BinaryLog复制依赖Lo ...

  3. Mysql 5.7 基于组复制(MySQL Group Replication) - 运维小结

    之前介绍了Mysq主从同步的异步复制(默认模式).半同步复制.基于GTID复制.基于组提交和并行复制 (解决同步延迟),下面简单说下Mysql基于组复制(MySQL Group Replication ...

  4. Mysql基于GTID复制模式-运维小结 (完整篇)

    先来看mysql5.6主从同步操作时遇到的一个报错:mysql> change master to master_host='192.168.10.59',master_user='repli' ...

  5. 基于amoeba实现mysql数据库的读写分离/负载均衡

    一.Amoeba的简述:[来自百度百科]      Amoeba是一个以MySQL为底层数据存储,并对应用提供MySQL协议接口的proxy.它集中地响应应用的请求,依据用户事先设置的规则,将SQL请 ...

  6. MySQL基于binlog主从复制

    MySQL复制介绍 默认情况 下复制是异步进行的,从库也不需要一直连接到主库来同步数据 MySQL复制的数据粒度可以是主实例上所有的数据库,也可以是指定的一个或多个数据库 ,也可以是一个数据库里的指定 ...

  7. 基于SSL实现Mysql加密主从

    Mysql主从复制是明文传输的,对于一些特殊的场合是绝对不允许的,数据的安全性会受到威胁,在这里,简单的构建基于SSL的mysql主从复制 Ps:这里采用master-mysql为CA服务器 主端生成 ...

  8. 基于Docker的Mysql主从复制搭建

    来源:https://www.cnblogs.com/songwenjie/p/9371422.html?tdsourcetag=s_pctim_aiomsg   为什么基于Docker搭建? 资源有 ...

  9. (转)基于keepalived搭建MySQL的高可用集群

    基于keepalived搭建MySQL的高可用集群  原文:http://www.cnblogs.com/ivictor/p/5522383.html MySQL的高可用方案一般有如下几种: keep ...

随机推荐

  1. ASP.net<a>标签跨页面传参数

    //在goodsDetail.aspx页面接收 <script> //加载事件 $(function () { //第一种方式 var id=GetQueryString("id ...

  2. SpringCloud-sleuth-zipkin链路追踪

    什么是Zipkin? 它是一个分布式链路跟踪系统它可以帮助收集时间数据,每个应用程序向Zipkin报告定时数据,Zipkin UI呈现了一个依赖图表来展示多少跟踪请求经过了每个应用程序:如果想解决延迟 ...

  3. Mybatis-plus快速入门

    简介 MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发.提高效率而生. 特性 无侵入:只做增强不做改变,引入它不会对现 ...

  4. Java开发笔记(八十二)注解的基本单元——元注解

    Java的注解非但是一种标记,还是一种特殊的类型,并且拥有专门的类型定义.前面介绍的五种内置注解,都可以找到对应的类型定义代码,例如查看注解@Override的源码,发现它的代码定义是下面这样的: @ ...

  5. centOS7下Spark安装配置

    环境说明: 操作系统: centos7 64位 3台 centos7-1 192.168.190.130 master centos7-2 192.168.190.129 slave1 centos7 ...

  6. PHP一些常用的正则表达式分享给大家

    一.校验数字的表达式 1 数字:^[0-9]*$2 n位的数字:^\d{n}$3 至少n位的数字:^\d{n,}$4 m-n位的数字:^\d{m,n}$5 零和非零开头的数字:^(0|[1-9][0- ...

  7. Java运行时数据区概述

    Java 虚拟机在执行Java程序的过程中会把它所管理的内存划分为若干个不同的数据区域,这些区域都有各自的用途,如图所示: 程序计数器 程序计数器是一块比较小的内存空间,可以看作是当前线程所执行的字节 ...

  8. Android 沉浸式状态栏完美解决方案

    现在搜索Android 沉浸式状态栏,真的是一堆一堆,写的特别多,但是真正用的舒服的真没有,在这里自己整理一下开发记录 注意,在使用这个步骤过程之前,请把之前设置的代码注释一下 把布局带有androi ...

  9. SQL SERVER 临时数据库 tempdb 迁移或增加文件

    临时数据库TempDB 虽然是临时库,但对整个数据库系统性能却起到很关键的作用:平时用到的中间数据集会暂时保存到TempDB 中,比如:临时表,排序,临时统计信息,一些中间结果数据,索引重建 等.我们 ...

  10. 解决Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile

    原因: 由于项目所需jdk版本和你当前使用的jdk版本不一致导致的,因为我项目的pom.xml中定义了java版本为1.8,但是我实际idea中run这个项目却是1.7 解决方案: 更换当前jdk版本 ...