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

注意:

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-binlog-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='123',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 * fromdb01.table03;+------+------+

| id | name |

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

| 1 | haha |

| 2 | wowo |

| 4 | yoyo |

| 1 | haha |

| 2 | wowo |

| 4 | yoyo |

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

6 rows in set (0.07sec)

slave查看:

mysql> select * fromdb01.table03;+------+------+

| id | name |

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

| 1 | haha |

| 2 | wowo |

| 4 | yoyo |

| 1 | haha |

| 2 | wowo |

| 4 | yoyo |

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

6 rows in set (0.07sec)

master插入数据并查看:

mysql> insert into db01.table03 values(5,'ouou');

Query OK,1 row affected (0.04sec)

mysql> select * fromdb01.table03;+------+------+

| id | name |

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

| 1 | haha |

| 2 | wowo |

| 4 | yoyo |

| 1 | haha |

| 2 | wowo |

| 4 | yoyo |

| 5 | ouou |

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

7 rows in set (0.00sec)

slave查看:

mysql> select * fromdb01.table03;+------+------+

| id | name |

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

| 1 | haha |

| 2 | wowo |

| 4 | yoyo |

| 1 | haha |

| 2 | wowo |

| 4 | yoyo |

| 5 | ouou |

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

7 rows in set (0.00sec)

并且master上面操作后查看slave的状态,下面就会有事务产生

mysql>show slave statusG;

Retrieved_Gtid_Set: 5624c184-5b55-11e8-b117-000c293dfd08:1Executed_Gtid_Set: 5624c184-5b55-11e8-b117-000c293dfd08:1Auto_Position:1

go mysql slave_MySQL基于GTIDs的MySQL Replication-Go语言中文社区相关推荐

  1. centos 6.6 mysql5.7_CentOS 6.5/6.6 安装(install)mysql 5.7 最完整版教程-Go语言中文社区...

    CentOS 6.5/6.6 安装(install)mysql 5.7 最完整版教程 Step1: 检测系统是否自带安装mysql [root@Ting ~]#   yum list installe ...

  2. windows下统一mysql编码_mysql5.7 windows7编码统一utf-8-Go语言中文社区

    查看mysql数据编码 登录mysql服务,查看mysql数据库默认的编码 mysql> show variables like 'character%'; +----------------- ...

  3. centos下安装mysql选什么版本_CentOS 7 安装MySQL 5.7 或安装指定版本MySQL-Go语言中文社区...

    1 摘要 目前(2019)年,MySQL 的最新版本为 MySQL 8.0 ,然而很多项目中依然使用的是 MySQL 5.7,个人开发环境中为了和线上项目数据库保持一致,也需要安装相同版本的 MySQ ...

  4. go连接mysql集群_Mysql集群方案-Go语言中文社区

    MySql集群原理 比如有三台mysql,当java使用数据源连接池进行连接的时候,应该连接哪台呢?其实连接哪台都不行,万一你连接的mysql,突然宕机了,那么数据都查询不到了,其实应该连接mycat ...

  5. go语言mysql删除记录_MySQL数据库删除操作-Go语言中文社区

    删除数据库 DROP DATABASE [IF EXISTS] 数据库名; 例如:删除school数据库 IF EXISTS 为可选,判断是否存在,如果不存在则会抛出异常 删除数据表 DROP TAB ...

  6. 用mysql创建职工表_【典型例题】数据库——用MySQL来建立创建员工表;-Go语言中文社区...

    作业: 创建员工表(employee),要求包含字段(工号.姓名.年龄.性别.薪资.部门),主键为工号. 要求命令行完成以下操作:(禁止使用图形工具软件) 1)添加三条员工信息 分别是: 1,张三,1 ...

  7. mac mysql my.cnf无效_mac 中 mysql 配置my.cnf无效解决办法-Go语言中文社区

    mac下mysql在/etc下配置my.cnf无效 网上也没搜到 翻官网文档说是默认配置信息在以下plist中 sudo vim /Library/LaunchDaemons/com.oracle.o ...

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

    基于Docker的Mysql主从复制搭建 为什么基于Docker搭建? 资源有限 虚拟机搭建对机器配置有要求,并且安装mysql步骤繁琐 一台机器上可以运行多个Docker容器 Docker容器之间相 ...

  9. mysql数据库基于gtid复制,mysql基于gtid复制的错误解决

    1.错误描述 Last_SQL_Errno: 1032 Last_SQL_Error: Coordinator stopped because there were error(s) in the w ...

最新文章

  1. 独家 | Bamboolib:你所见过的最有用的Python库之一(附链接)
  2. Linux系统抓包命令tcpdump使用实例
  3. apache+tomcat的架构
  4. 怎么快速写python自动化脚本_自动化脚本如何编写?
  5. python列表和字典_2020/11/18 python学习第5课 列表和字典
  6. 聚焦IT系统稳定性保障服务 PerfMa笨马网络完成亿元级B轮融资
  7. python初学者必背函数_新手必看python vlog 1: 函数
  8. 员工主动辞职公司也要支付经济补偿金的17种情况
  9. 为什么C#有委托,而Java没有?
  10. C#中@的用法总结(转)
  11. 百度快速排名 24小时进前五 刷网站排名
  12. 基于51单片机的电子记分牌的设计
  13. dhcp计算机毕业论文,计算机网络毕业设计(论文)dhcp在校园网中的应用.pdf
  14. VScode 常用插件推荐
  15. Kaggle数据集之电信客户流失数据分析
  16. SQL防注入大全——史上最全的 SQL 注入资料
  17. CAD7:构造线的使用 【TR剪掉多余的线】
  18. 【自建题库】c认证初级
  19. 可用的公开 RTSP/ RTMP 在线视频流资源地址
  20. 红米1S联通版_标注:2013029_官方线刷包_救砖包_解账户锁

热门文章

  1. Python3匿名函数字典排序、生成式与生成器、装饰器简介
  2. pycharm pro版本激活
  3. 悲哀!面试现场,简单几道java算法题,90%程序员没写出来
  4. Node.js:清理项目中的依赖
  5. NOI OpenJudge 8469 特殊密码锁 Label贪心
  6. ionic 上拉加载更多
  7. 结构体数组(C++)
  8. jocky1.0.3 (原joc) java混淆器 去除jdk版本限制
  9. malloc在函数内分配内存问题
  10. 给Lisp程序员的Python简介