mysql GTID

master:

[mysqld]
port=3306
datadir=/3306/data
socket=/3306/mysql.sock
log-error=/3306/log/db.log
log-bin=/3306/mysql-bin
server-id=1
gtid-mode=ON
enforce-gtid-consistency=ON
[mysqld_safe]
log-error=/3306/log/db.log
pid-file=/3306/run/db.pid

--新建用户就可以:
grant replication slave on . to 'rep'@'192.168.3.%' identified by '123';
flush privileges;

slave:

[mysqld]
port=3333
datadir=/3333/data
socket=/3333/mysql.sock
server-id=100
gtid-mode=ON
enforce-gtid-consistency=ON
log-bin=/3333/mysql-bin
[mysqld_safe]
log-error=/3333/log/db.log
pid-file=/3333/run/db.pid

--指定复制信息
change master to master_host='192.168.3.201', master_user='rep',master_password='123',master_port=3306,master_auto_position=1;
start slave;
show slave status\G;

MySQL 5.6版本开启GTID模式,必须打开参数log_slave_updates.在MySQL 5.6中必须配置参数log_slave_updates的最重要原因在于当slave重启后,无法得知当前slave已经运行到的GTID位置,因为变量gtid_executed是一个内存值:

MySQL 5.7版本开始无需在GTID模式下启用参数log_slave_updates,.7在mysql库下引入了新的表gtid_executed.

在线关闭:

GTID

gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates = 1

备库执行:
stop slave;
change master to master_host='192.168.3.201', master_user='rep',master_password='123',master_port=3306,master_auto_position=0;
start slave;

主备依次设置GTID_MODE为ON_PERMISSIVE、OFF_PERMISSIVE
set @@global.gtid_mode=ON_PERMISSIVE;
set @@global.gtid_mode=OFF_PERMISSIVE;
主备库关闭GTID
SET @@GLOBAL.GTID_MODE = OFF;

修改my.cnf配置文件(关闭GTID参数)

gtid_mode = on

enforce_gtid_consistency = 1

log_slave_updates = 1

在线开启(所有实例上执行)

set global ENFORCE_GTID_CONSISTENCY = ON;

(主从复制结构中所有实例中执行)

set global GTID_MODE = OFF_PERMISSIVE;
set global GTID_MODE = ON_PERMISSIVE;
//SHOW STATUS LIKE 'ONGOING_ANONYMOUS_TRANSACTION_COUNT';
//show slave status 检查应用位点的情况;
set global GTID_MODE = ON;

stop slave;
CHANGE MASTER TO MASTER_AUTO_POSITION = 1;
start slave;

修改my.cnf 添加

gtid_mode = on
enforce_gtid_consistency = on

master:

[mysqld]
port=3306
datadir=/3306/data
socket=/3306/mysql.sock
log-error=/3306/log/db.log
log-bin=/3306/mysql-bin
server-id=1
gtid-mode=ON
enforce-gtid-consistency=ON
[mysqld_safe]
log-error=/3306/log/db.log
pid-file=/3306/run/db.pid

--新建用户就可以:
grant replication slave on . to 'rep'@'192.168.3.%' identified by '123';
flush privileges;

slave:

[mysqld]
port=3333
datadir=/3333/data
socket=/3333/mysql.sock
server-id=100
gtid-mode=ON
enforce-gtid-consistency=ON
log-bin=/3333/mysql-bin
[mysqld_safe]
log-error=/3333/log/db.log
pid-file=/3333/run/db.pid

--指定复制信息
change master to master_host='192.168.3.201', master_user='rep',master_password='123',master_port=3306,master_auto_position=1;
start slave;
show slave status\G;

MySQL 5.6版本开启GTID模式,必须打开参数log_slave_updates.在MySQL 5.6中必须配置参数log_slave_updates的最重要原因在于当slave重启后,无法得知当前slave已经运行到的GTID位置,因为变量gtid_executed是一个内存值:

MySQL 5.7版本开始无需在GTID模式下启用参数log_slave_updates,.7在mysql库下引入了新的表gtid_executed.

在线关闭:

GTID

gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates = 1

备库执行:
stop slave;
change master to master_host='192.168.3.201', master_user='rep',master_password='123',master_port=3306,master_auto_position=0;
start slave;

主备依次设置GTID_MODE为ON_PERMISSIVE、OFF_PERMISSIVE
set @@global.gtid_mode=ON_PERMISSIVE;
set @@global.gtid_mode=OFF_PERMISSIVE;
主备库关闭GTID
SET @@GLOBAL.GTID_MODE = OFF;

修改my.cnf配置文件(关闭GTID参数)

gtid_mode = on

enforce_gtid_consistency = 1

log_slave_updates = 1

在线开启(所有实例上执行)

set global ENFORCE_GTID_CONSISTENCY = ON;

(主从复制结构中所有实例中执行)

set global GTID_MODE = OFF_PERMISSIVE;
set global GTID_MODE = ON_PERMISSIVE;
//SHOW STATUS LIKE 'ONGOING_ANONYMOUS_TRANSACTION_COUNT';
//show slave status 检查应用位点的情况;
set global GTID_MODE = ON;

stop slave;
CHANGE MASTER TO MASTER_AUTO_POSITION = 1;
start slave;

修改my.cnf 添加

gtid_mode = on
enforce_gtid_consistency = on

上一篇:MySQL Group Commit


下一篇:mysql超时设置