mysql基于GTID搭建主从复制

gtid的含义
Global Transaction Identifier,全局事务标识
阿里云的rds目前已经使用gtid

基于gtid的主从复制原理
每个mysql数据库上都有一个唯一uuid
每个事务生成一个id
gtid由上面两者组合: uuid+事务id

相对使用binlog+位置的方法来说
gtid让配置主从更加方便
从提升为主时比较方便

主从库的配置一样,实践中的版本5.6.41
gtid_mode=on
enforce_gtid_consistency=on
log-slave-updates=1
log-bin=master-bin
log-bin-index = master-bin.index
relay-log = relay-log
relay-log-index = relay-log.index
binlog_format=row

查看数据库的uuid
在数据目录的auto.cnf
在mysql里面使用命令查看show global variables like 'server_uuid'

主库给从库复制权限
grant replication slave on . to 'replication'@'192.168.237.129' identified by 'shijiange';
flush privileges;

从库使用命令进行复制
change master to
master_host='192.168.237.128',
master_port=3306,
master_user='replication',
master_password='shijiange',
master_auto_position = 1;

主从的binlog日志观察
show binlog events in 'master-bin.000001';

增加数据来验证是否同步成功
create database shijiange;
use shijiange;
create table test (id int);
insert into test values (1);
update test set id = 3 where id = 1;
delete from test;
drop database shijiange;

猜你喜欢

转载自blog.51cto.com/14036860/2483802