mysql基于GTID主从搭建



#************************master 添加配置(XXX.XXX.XXX.204) ************************
#开启二进制日志
bin-log=master-bin
#开启gtid模块
gtid-mode=on
#开启强制gtid一致性,
enforce-gtid-consistency=on 
#指定日志的记录模式为row(行记录),确保数据的一致性
binlog-format=row
#开启从服务器日志更新,从服务器中的操作记录也将写入日志文件中
log-slave-updates=1         
#启用自动开启主从复制
skip-slave-start=1 

service mysqld restart 

grant replication slave on *.* to 'slave'@'%' identified by 'passwd';



#************************ slave 添加配置(XXX.XXX.XXX.201) ************************
#server-id=3
gtid-mode=on
#开启强制gtid一致性,
enforce-gtid-consistency=on 
#指定日志的记录模式为row(行记录),确保数据的一致性
binlog-format=row
#开启从服务器日志更新,从服务器中的操作记录也将写入日志文件中
log-slave-updates=1         
#启用自动开启主从复制
skip-slave-start=1 



stop slave;
reset slave all;
change master to master_host="XXX.XXX.XXX.204",master_user="slave",master_password="passwd",master_auto_position=1;
start slave; 
 #查看状态
 show slave status\G;
 报错
                Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.


首先检查server-id要不一样否则也会有问题
查看uuid是否一致 
(XXX.XXX.XXX.201)和 (XXX.XXX.XXX.204)uuid一样
 show variables like '%server_uuid%';
+---------------+--------------------------------------+
| Variable_name | Value                                |
+---------------+--------------------------------------+
| server_uuid   | 542a25ae-4d5f-11ee-a6d7-000c2995a003 |
+---------------+--------------------------------------+
1 row in set (0.05 sec)

show variables like '%server_uuid%';
+---------------+--------------------------------------+
| Variable_name | Value                                |
+---------------+--------------------------------------+
| server_uuid   | 542a25ae-4d5f-11ee-a6d7-000c2995a003 |
+---------------+--------------------------------------+
1 row in set (0.05 sec)
				
修改uuid重启报错
[ERROR] Garbage characters found at the end of the server_uuid value in auto.cnf file. It should be of length '36' (UUID_LENGTH). Clear it and restart the server. 
2023-11-21T08:46:15.916691Z 0 [ERROR] Initialization of the server's UUID failed because it could not be read from the auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID.
2023-11-21T08:46:15.916694Z 0 [ERROR] Aborting
删除重启
cd /usr/local/mysql5.7/data				
rm -rf auto.cnf 
service mysqld restart
 start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: XXX.XXX.XXX.204
                  Master_User: slave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000018
          Read_Master_Log_Pos: 154
               Relay_Log_File: localhost-relay-bin.000003
                Relay_Log_Pos: 361
        Relay_Master_Log_File: binlog.000018
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 


总结:server-id 不一样  uuid不一样			  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值