mysql基于日志和gtid复制配置和切换

环境:
主server:win10,mysql verison 5.7.21,ip:192.168.0.100,port:3306
从server:redhat6.4,mysql version 5.7.22,ip:192.168.0.101,port:3306

一.基于日志的复制:

1.主从上:
 show variables like '%bin%'; 开启bin的日志
 没有开启的话,主从上要加入:
                 server-id=2
                 log-bin=mybinlogg
 后重启从mysql服务 

2.主上:

create user 'yorep'@'%' identified by '123456';
grant replication slave on *.* to 'yorep'@'%';
mysqldump --single-transaction --master-data=2 --all-databases -uroot -p > all.sql

3.copy all.sql到从上:
mysql -uroot -ppassword < all.sql

4.从上:
change master to master_host='192.168.0.100',master_user='yorep',master_password='123456',MASTER_LOG_FILE='mybinlog.000011', MASTER_LOG_POS=787;

start slave;

5.查看复制状态:

从上:
use performance_schema;
show tables like '%replication%';
select * from replication_applier_status;
select * from replication_applier_configuration;
select * from replication_connection_configuration \G;
show slave status\G;
show full processlist;

主上:
show full processlist;
show master status;

二.在线把基于日志的复制改成基于gtid的复制

1.主从上:
  show variables like '%gtid%';  gtid的参数是循序渐进的修改的不能一步改成on
  set global enforce_gtid_consistency=warn; 查看/var/log/mysqld.log是否有错误
  set global enforce_gtid_consistency=on;
  set global gtid_mode=off_permissive;查看/var/log/mysqld.log是否有错误
  set global gtid_mode=on_permissive;

2.从上:
  show status like '%anonymous%'; 等基于日志复制的队列为空

3.主从上:
   set global gtid_mode=on;

4.从上:
  stop slave;
  change master to master_auto_position=1;
  start slave;
  show slave status;

三.在线把gtid的复制变成基于日志的复制:

1.从上:

先show slave status查看当前的复制日志点,log_file和log_pos
stop slave;
change master to master_auto_position=0,MASTER_LOG_FILE='mybinlog.000014', MASTER_LOG_POS=416;
start slave;

2.主从:
 set global gtid_mode=on_permissive;
 set global gtid_mode=off_permissive;
  从上查看:show variables like '%gtid_owned%';需要为空
 set global gtid_mode=off;



你可能感兴趣的:(MYSQL)