mysql gtid 还是pxc_PXC中的GTIDs

article/2025/9/14 18:22:12

基本环境:PXC 5.7.19 Row+Gtid,3节点

一、Galera GTID vs MySQL GTID

1.1、Galera GTID vs MySQL GTID

Both kinds of GTIDs are using the same format: .

For Galera, is generated when the cluster is bootstrapped. This is shared by all nodes.

For MySQL, is the server uuid. So it is easy to identify from which server a transaction originates.

我们先来看下PXC环境Galera GTID和MySQL GTID分别指的是什么

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

# node1的server_uuid

mydba@192.168.85.132,3326 [replcrash]> select @@server_uuid;+--------------------------------------+

| @@server_uuid |

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

| 31304898-67d8-11e8-bb20-000c29c1025c |

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

1 row in set (0.00sec)

# node1写入一条数据

mydba@192.168.85.132,3326 [replcrash]> insert into py_user(name,add_time,server_id) select left(uuid(),32),now(),@@server_id;

Query OK,1 row affected (0.02sec)

Records:1 Duplicates: 0 Warnings: 0# node1查看gtid_executed

mydba@192.168.85.132,3326 [replcrash]> select @@global.gtid_executed;+----------------------------------------+

| @@global.gtid_executed |

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

| 0f0f1664-9769-ee17-7834-ec71884d9f25:1 |

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

1 row in set (0.00sec)

# node2的server_uuid

mydba@192.168.85.133,3326 [replcrash]> select @@server_uuid;+--------------------------------------+

| @@server_uuid |

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

| 570e2242-6898-11e8-bcae-000c2900c99c |

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

1 row in set (0.01sec)

# node2写入一条数据

mydba@192.168.85.133,3326 [replcrash]> insert into py_user(name,add_time,server_id) select left(uuid(),32),now(),@@server_id;

Query OK,1 row affected (0.45sec)

Records:1 Duplicates: 0 Warnings: 0# node2查看gtid_executed

mydba@192.168.85.133,3326 [replcrash]> select @@global.gtid_executed;+------------------------------------------+

| @@global.gtid_executed |

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

| 0f0f1664-9769-ee17-7834-ec71884d9f25:1-2 |

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

1 row in set (0.00 sec)

View Code

上面@@server_uuid对应的是MySQL,@@global.gtid_executed对应的是Galera

node1、node2上执行的insert语句使用相同的,仿佛它们在同一台实例上执行,并且与node1/node2自己的@@server_uuid不同

我们可以把Cluster当作MySQL复制中的Master,所有节点获取来自相同的数据

1.2、UUID

我们知道MySQL GTID的存储于$/datadir/auto.cnf,Galera GTID的是否也存在相关的文件?如果你足够仔细的话,你会发现Galera GTID与$/datadir/grastate.dat存在下面的关联

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

# 查看grastate.dat

[root@ZST1 data]#catgrastate.dat

# GALERA saved state

version:2.1uuid: f0f0e99b-6896-11e8-87cb-138e77b260da

seqno:-1safe_to_bootstrap:0[root@ZST1 data]#

# Galera GTID与$/datadir/grastate.dat的关联

Galera GTID + grastate.dat

= 0f0f1664-9769-ee17-7834-ec71884d9f25 + f0f0e99b-6896-11e8-87cb-138e77b260da= ffffffff-ffff-ffff-ffff-ffffffffffff

View Code

Cluster的第一节点启动时,会读取grastate.dat文件,用它里面的uuid信息构建Galera GTID的。如果删除$/datadir/grastate.dat文件,下次重新启动集群,它的Galera GTID会改变(类似删除$/datadir/auto.cnf文件,重新启动实例MySQL GTID也会改变)。Galera GTID与MySQL GTID之间并没有对应关系,它们是相互独立的。PXC中的@@global.gtid_executed的初始化可以参考:gtid_executed和gtid_purged变量是如何初始化的,只要明白Galera GTID的来源,其他完全可以套用MySQL GTID

PXC中其实还存在其他uuid

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

mydba@192.168.85.132,3326 [replcrash]> show status like '%uuid%';+--------------------------+--------------------------------------+

| Variable_name | Value |

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

| wsrep_local_state_uuid | f0f0e99b-6896-11e8-87cb-138e77b260da |

| wsrep_gcomm_uuid | 8ab36be3-6897-11e8-bf70-cee6630daa30 |

| wsrep_cluster_state_uuid | f0f0e99b-6896-11e8-87cb-138e77b260da |

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

3 rows in set (0.00sec)

wsrep_cluster_state_uuid

Provides thecurrent State UUID. This is a unique identifier for the current state of the cluster and the sequence ofchanges it undergoes.

wsrep_local_state_uuid

The UUIDof the state stored onthis node.

wsrep_gcomm_uuid

Displays thegroup communications UUID.

View Code

wsrep_cluster_state_uuid、wsrep_local_state_uuid对应的就是grastate.dat中的uuid,wsrep_gcomm_uuid是group communications uuid

二、什么情况下当前节点的事务不会复制到其他节点

普通主从环境,从库@@global.gtid_executed只会显示主库执行的事务。如果我们在从库手动执行事务,那么从库@@global.gtid_executed就会包含本地的信息

对于PXC来说,它支持多节点写入,任何节点的DML操作先在本地执行,在提交前将所有的变更和对应主键保存到write-set,集群下发write-set给每个节点(包括DML执行的节点),使用主键验证各节点是否可以应用write-set。如果验证失败,则删除write-set并回滚原始事务;如果验证成功,提交事务并应用其他未完成的write-set。

是不是任何节点上的任何事务都能复制所有节点?有没有可能某个事务只存在于一个节点?

• DML On MyISAM

最大的可能是对MyISAM表的DML操作,会使用server_uuid记录binlog,并且不会被复制到集群中的其他节点!

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

# node1创建myisam引擎的表

mydba@192.168.85.132,3326 [replcrash]> create table py_user_myisam(id int not null primary key) engine=myisam;

Query OK,0 rows affected (0.66sec)

# 往py_user_myisam表中插入数据

mydba@192.168.85.132,3326 [replcrash]> insert into py_user_myisam(id) select 1;

ERROR1105 (HY000): Percona-XtraDB-Cluster prohibits use of DML command on a table (replcrash.py_user_myisam) that resides in non-transactional storage engine with pxc_strict_mode = ENFORCING orMASTER

# 修改mode为permissive

mydba@192.168.85.132,3326 [replcrash]> set global pxc_strict_mode='permissive';

Query OK,0 rows affected (0.00sec)

# 重新插入数据

mydba@192.168.85.132,3326 [replcrash]> insert into py_user_myisam(id) select 1;

Query OK,1 row affected, 1 warning (0.09sec)

Records:1 Duplicates: 0 Warnings: 1# node1查看gtid_executed

mydba@192.168.85.132,3326 [replcrash]> select @@global.gtid_executed;+----------------------------------------------------------------------------------+

| @@global.gtid_executed |

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

| 0f0f1664-9769-ee17-7834-ec71884d9f25:1-3,31304898-67d8-11e8-bb20-000c29c1025c:1 |

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

1 row in set (0.00sec)

# 查看binlog events

mydba@192.168.85.132,3326 [replcrash]> show binlog events in 'mysql-bin.000003';+------------------+-----+----------------+-----------+-------------+-----------------------------------------------------------------------------------------+

| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |

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

| mysql-bin.000003 | 4 | Format_desc | 1323326 | 123 | Server ver: 5.7.19-17-29.22-log, Binlog ver: 4 |

| mysql-bin.000003 | 123 | Previous_gtids | 1323326 | 194 | 0f0f1664-9769-ee17-7834-ec71884d9f25:1 |

| mysql-bin.000003 | 194 | Gtid | 1333326 | 259 | SET @@SESSION.GTID_NEXT= '0f0f1664-9769-ee17-7834-ec71884d9f25:2' |

| mysql-bin.000003 | 259 | Query | 1333326 | 327 | BEGIN |

| mysql-bin.000003 | 327 | Table_map | 1333326 | 390 | table_id: 121 (replcrash.py_user) |

| mysql-bin.000003 | 390 | Write_rows | 1333326 | 476 | table_id: 121 flags: STMT_END_F |

| mysql-bin.000003 | 476 | Xid | 1333326 | 507 | COMMIT /*xid=3*/ |

| mysql-bin.000003 | 507 | Gtid | 1323326 | 572 | SET @@SESSION.GTID_NEXT= '0f0f1664-9769-ee17-7834-ec71884d9f25:3' |

| mysql-bin.000003 | 572 | Query | 1323326 | 726 | use `replcrash`; create table py_user_myisam(id int not null primary key) engine=myisam |

| mysql-bin.000003 | 726 | Gtid | 1323326 | 791 | SET @@SESSION.GTID_NEXT= '31304898-67d8-11e8-bb20-000c29c1025c:1' |

| mysql-bin.000003 | 791 | Query | 1323326 | 873 | BEGIN |

| mysql-bin.000003 | 873 | Table_map | 1323326 | 935 | table_id: 224 (replcrash.py_user_myisam) |

| mysql-bin.000003 | 935 | Write_rows | 1323326 | 975 | table_id: 224 flags: STMT_END_F |

| mysql-bin.000003 | 975 | Query | 1323326 | 1058 | COMMIT |

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

14 rows in set (0.05sec)

# node2查看gtid_executed

mydba@192.168.85.133,3326 [replcrash]> select @@global.gtid_executed;+------------------------------------------+

| @@global.gtid_executed |

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

| 0f0f1664-9769-ee17-7834-ec71884d9f25:1-3 |

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

1 row in set (0.10 sec)

View Code

创建MyISAM表的语句使用DDL机制,它能复制到各节点;但是对MyISAM表执行DML操作,它使用@@server_uuid(类似常规MySQL复制),不会复制到Cluster的其他节点,但是它能复制到node1节点的异步Slave

• Flush Commands

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

# node1执行flush privilegesmydba@192.168.85.132,3326 [replcrash]> flush privileges;

Query OK,0 rows affected (0.26sec)

# node1查看gtid_executed

mydba@192.168.85.132,3326 [replcrash]> select @@global.gtid_executed;+----------------------------------------------------------------------------------+

| @@global.gtid_executed |

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

| 0f0f1664-9769-ee17-7834-ec71884d9f25:1-4,31304898-67d8-11e8-bb20-000c29c1025c:1 |

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

1 row in set (0.00sec)

# node1查看binlog events

mydba@192.168.85.132,3326 [replcrash]> show binlog events in 'mysql-bin.000003';+------------------+------+----------------+-----------+-------------+-----------------------------------------------------------------------------------------+

| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |

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

| mysql-bin.000003 | 4 | Format_desc | 1323326 | 123 | Server ver: 5.7.19-17-29.22-log, Binlog ver: 4 |

| mysql-bin.000003 | 123 | Previous_gtids | 1323326 | 194 | 0f0f1664-9769-ee17-7834-ec71884d9f25:1 |

| mysql-bin.000003 | 194 | Gtid | 1333326 | 259 | SET @@SESSION.GTID_NEXT= '0f0f1664-9769-ee17-7834-ec71884d9f25:2' |

| mysql-bin.000003 | 259 | Query | 1333326 | 327 | BEGIN |

| mysql-bin.000003 | 327 | Table_map | 1333326 | 390 | table_id: 121 (replcrash.py_user) |

| mysql-bin.000003 | 390 | Write_rows | 1333326 | 476 | table_id: 121 flags: STMT_END_F |

| mysql-bin.000003 | 476 | Xid | 1333326 | 507 | COMMIT /*xid=3*/ |

| mysql-bin.000003 | 507 | Gtid | 1323326 | 572 | SET @@SESSION.GTID_NEXT= '0f0f1664-9769-ee17-7834-ec71884d9f25:3' |

| mysql-bin.000003 | 572 | Query | 1323326 | 726 | use `replcrash`; create table py_user_myisam(id int not null primary key) engine=myisam |

| mysql-bin.000003 | 726 | Gtid | 1323326 | 791 | SET @@SESSION.GTID_NEXT= '31304898-67d8-11e8-bb20-000c29c1025c:1' |

| mysql-bin.000003 | 791 | Query | 1323326 | 873 | BEGIN |

| mysql-bin.000003 | 873 | Table_map | 1323326 | 935 | table_id: 224 (replcrash.py_user_myisam) |

| mysql-bin.000003 | 935 | Write_rows | 1323326 | 975 | table_id: 224 flags: STMT_END_F |

| mysql-bin.000003 | 975 | Query | 1323326 | 1058 | COMMIT |

| mysql-bin.000003 | 1058 | Gtid | 1323326 | 1123 | SET @@SESSION.GTID_NEXT= '0f0f1664-9769-ee17-7834-ec71884d9f25:4' |

| mysql-bin.000003 | 1123 | Query | 1323326 | 1219 | use `replcrash`; flush privileges |

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

16 rows in set (0.00sec)

# node2查看gtid_executed

mydba@192.168.85.133,3326 [replcrash]> select @@global.gtid_executed;+------------------------------------------+

| @@global.gtid_executed |

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

| 0f0f1664-9769-ee17-7834-ec71884d9f25:1-4 |

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

1 row in set (0.00sec)

# node2查看binlog events

mydba@192.168.85.133,3326 [replcrash]> show binlog events in 'mysql-bin.000004';+------------------+-----+----------------+-----------+-------------+-----------------------------------------------------------------------------------------+

| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |

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

| mysql-bin.000004 | 4 | Format_desc | 1333326 | 123 | Server ver: 5.7.19-17-29.22-log, Binlog ver: 4 |

| mysql-bin.000004 | 123 | Previous_gtids | 1333326 | 194 | 0f0f1664-9769-ee17-7834-ec71884d9f25:1 |

| mysql-bin.000004 | 194 | Gtid | 1333326 | 259 | SET @@SESSION.GTID_NEXT= '0f0f1664-9769-ee17-7834-ec71884d9f25:2' |

| mysql-bin.000004 | 259 | Query | 1333326 | 349 | BEGIN |

| mysql-bin.000004 | 349 | Table_map | 1333326 | 412 | table_id: 121 (replcrash.py_user) |

| mysql-bin.000004 | 412 | Write_rows | 1333326 | 498 | table_id: 121 flags: STMT_END_F |

| mysql-bin.000004 | 498 | Xid | 1333326 | 529 | COMMIT /*xid=3*/ |

| mysql-bin.000004 | 529 | Gtid | 1323326 | 594 | SET @@SESSION.GTID_NEXT= '0f0f1664-9769-ee17-7834-ec71884d9f25:3' |

| mysql-bin.000004 | 594 | Query | 1323326 | 748 | use `replcrash`; create table py_user_myisam(id int not null primary key) engine=myisam |

| mysql-bin.000004 | 748 | Gtid | 1323326 | 813 | SET @@SESSION.GTID_NEXT= '0f0f1664-9769-ee17-7834-ec71884d9f25:4' |

| mysql-bin.000004 | 813 | Query | 1323326 | 909 | use `replcrash`; flush privileges |

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

11 rows in set (0.00 sec)

View Code

实验表明,flush命令被正常复制到其他节点,binlog中使用的是Cluster UUID。看来Issuing FLUSH commands on a node will create a local transaction on GTID-configured clusters已经被修复●-●

• SQL_LOG_BIN=0

在当前节点 SET SQL_LOG_BIN=0,不会记录对应的binlog,难道就没有对应的write-set?这种情况对于事后也没办法知道原始事务发生在哪个节点,没GTID,没binlog,太阔怕・ω・

三、参考文档


http://chatgpt.dhexx.cn/article/qaf5x5qy.shtml

相关文章

mysql pxc搭建_MySQL(PXC)集群搭建

前言 我这里使用三台CentOS Linux release 7.8.2003的虚拟机来作演示 [rootn1 ~]# cat /etc/redhat-release CentOS Linux release 7.8.2003 (Core) 安装前准备 请确保服务器没有安装MySQL,如果已经安装了请先卸载(后面会起冲突) 删除 MariaDB 这里我的服务器版本为…

docker pxc mysql_docker安装pxc集群的详细教程

前言 现在mysql自建集群方案有多种,keepalived、MHA、PXC、MYSQL主备等,但是目前根据自身情况和条件,选择使用pxc的放来进行搭建,最大的好处就是,多主多备,即主从一体,没有同步延时问题&#xf…

mysql pxc gcache_MySQL高可用之PXC

PXC简介 PXC(Percona XtraDB Cluster)是一个开源的MySQL高可用解决方案。他将Percona Server和XtraBackup与Galera库集成,以实现同步多主复制。基于Galera的高可用方案主要有MariaDB Galera Cluster和Percona XtraDB Cluster,目前PXC架构在生产线上用的更…

PXC集群

1.pxc集群 1.1 软件介绍 • Percona XtraDB Cluster(简称PXC) - 是基于Galera的mysql高可用集群解决方案 - Galera Cluster是Codership公司开发的一套免费开源的高可用方案 - PXC集群主要由两部分组成:Percona Server with XtraDB和Write Set Replication patches(同步,多主复制…

mysql bootstrap pxc_Mysql高可用之PXC

一。PXC简介 Percona XtraDB Cluster简称PXC。是一套开源mysql高可用解决方案(XtraDb是mysql被oracle收购之前 开源一个分支 其他分支还有mariadb),Percona Xtradb Cluster的实现是在原mysql代码上通过Galera包将不同的mysql实例(新名称 Percona Server)连接起来&am…

mysql pxc 安装_MYSQL PXC 集群安装

名词介绍: WS:write set写数据集 IST: Incremental State Transfer增量同步 SST:State Snapshot Transfer全量同步 1.准备环境 1.1 centos 7系统,三台主机 IP分别为:192.168.80.163;192.168.80.167;192.168…

kubernetes mysql pxc_PXC快速入门

C C语言开发 PXC快速入门 1.快速入门 实验环境: Node Host IPNode1 pxc1 192.168.70.61 Node2 pxc2 192.168.70.62 Node3 pxc3 192.168.70.63 1.1 安装Percona-XtraDb-Cluster yum源: [percona] namepercona_repo baseurl https://mirrors.tuna.tsinghu…

mysql pxc

一、PXC介绍 Percona Server由领先的MySQL咨询公司Percona发布。 Percona Server是一款独立的数据库产品,其可以完全与MySQL兼容,可以在不更改代码的情况了下将存储引擎更换成XtraDB 。XtraDB可以看做是InnoDB存储引擎的增强版本,它完全兼容InnoDB,且提供了很多InnoDB不具…

mysql pxc集群 原理 (图解+秒懂+史上最全)

文章很长,而且持续更新,建议收藏起来,慢慢读! Java 高并发 发烧友社群:疯狂创客圈(总入口) 奉上以下珍贵的学习资源: 免费赠送 经典图书 : 极致经典 社群大片好评 《 …

什么是PXC?

目录 什么是PXC PXC的作用 PXC集群的注意事项 比较PXC模式和Replication(传统主从) 什么是PXC PXC是针对MySQL用户的高可用性和扩展性解决方案,基于Percona Server 。 Percona Server 是MySQL的改进版本,使用 XtraDB 存储引擎,在功能和性…

MySQL高可用之PXC详解

PXC 一、PXC相关简介二、部署PXC 一、PXC相关简介 1.pxc简介 PXC(Percona XtraDB Cluster)是一个开源的MySQL高可用解决方案。它将Percona server和XtraBackup与galera库集成,以实现同步多主复制。基于galera的高可用方案主要有MariaDB gale…

小马激活工具拒绝访问cannot open file c:\oemsf解决方法

第一步、激活本机的管理员帐号(administrator),进入命令行窗口(WinKeyR 出现运行窗口,输入“cmd”,按确定),输入以下命令:net user administrator /active:yes。 第二步、使用管理员帐号(administrator)登录系统&am…

小马激活工具对比暴风激活工具

提到win7激活工具,人气最旺的就是:小马激活工具和暴风激活工具。那么,这两款win7激活工具哪个好呢?在今天的教程中,小编就给大家分享一下win7激活工具:小马激活工具和暴风激活工具的使用过程对比&#xff0…

使用小马哥win10 激活工具激活后, 桌面上经常出现一个广告快捷方式的 解决方法...

【本文首发在 梦溪笔记 http://www.mengxi.me 】 小马哥的win10 激活工具 可以一键激活win10, 使用方便,还有效, 但是也存在个人很讨厌的打广告行为, 每次电脑启动时, 会在桌面上创建一个垃圾网站的快捷方式, 图标长的…

小马激活工具出现Cannot open file k:\OEMSF 的解决方法

遇到“此windows副本不是正版7601”,我们一般用小马激活软件激活一下就可以了。但是有时候可能不管用,会显示“Cannot open file OEMSF”的错误,那么我们该怎么解决呢?不用担心,下面就为大家介绍一下,一起来…

很抱歉 程序无法在非mbr引导的分区上激活

很抱歉 程序无法在非mbr引导的分区上激活 [Windows] 神器。完美解决非MBR引导下的WIN7激活问题。你会用的到的 才帮同事装了个系统,发现有100M的隐藏分区。 小马等其他激活工具都激活不了。提示非MBR引导无法激活。 找到了这个激活工具,完美解决。 链…

小马激活手动分配磁盘_不要成为“单把小马”手动测试仪

小马激活手动分配磁盘 我记得我父母带我去马戏团时见过小马。 它们是节目的重要组成部分,以敏捷,跳过障碍物和用两只脚走路给观众留下了深刻的印象。 小马的表演是如此多样,即使您连续几天参加演出,也很难对此感到无聊。 但是让…

使用小马激活工具激活Windows后,浏览器的首页被篡改,如何改回去?

方法一 直接修改浏览器的名字,这种事最简单的方法,KMS(小马激活工具)通过搜索相关的关键字。比如chrome、google、360等一些主流浏览器,对其进行动态代码注入。 方法二 通过WMI(Windows Management Inst…

小马激活软件下载,当心伪小马,有病毒

官方的小马激活软件已经停止更新了,下文是官方停更公告。 http://www.pccppc.com/xiaomajihuo-html 所以小马oem7以后的都不是官方的,包含病毒。重装系统后,一般是先激活系统,再安装杀毒软件,这就给“伪小马激活工具”…

电脑系统或者office系列使用小马激活工具,电脑开机桌面出现假的Edge浏览器

步骤: 首先,在电脑搜索栏里搜索“计划任务” 然后,点击计划任务,打开 最后,关掉有关KMS的计划,右侧的禁用