环境:
OS:Centos 7
mysql:5.7.29
1.停止从服务器slave服务:
mysql> stop slave;
2.将从服务器切换为主服务器,在从服务器上执行
mysql> reset master;
mysql> reset slave all;
3.这个时候查看下新主库的gtid
mysql> show slave status \G; Empty set (0.00 sec) ERROR: No query specified mysql> show master status \G; *************************** 1. row *************************** File: binlog.000001 Position: 154 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 1 row in set (0.00 sec) ERROR: No query specified
4.设置新主库可写(原来只读)
set global read_only=off;
5.新主库模拟写入数据
mysql> use db_test;
insert into tb_test values(14,'name14'),(15,'name15'),(16,'name16');
insert into tb_test values(17,'name17'),(18,'name18'),(19,'name19');
这个时候的事务情况:
mysql> show master status \G; *************************** 1. row *************************** File: binlog.000001 Position: 452 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 823a206f-3502-11ee-8c3a-52540051cd25:1 1 row in set (0.00 sec) ERROR: No query specified
5.启动原来的主库,使其变成从库
/data/middle/mysql57/bin/mysqld_safe --defaults-file=/data/middle/mysql57/conf/my.cnf --user=mysql &
/data/middle/mysql57/bin/mysql -h localhost -uroot -P13306 -pmysql
change master to master_host='192.168.1.134', master_user='ureplsync', master_password='my6sq#7Rte', master_port=13306, master_auto_position=1; start slave;
6.这个时候在从库下验证新主库新写入的数据是否同步过来
标签:主库,Binlog,slave,Auto,主备,mysql,master,row From: https://www.cnblogs.com/hxlasky/p/17617515.html