非gtid模式,主从切换
主mysql进行锁表
flush tables with read lock;
show full processlist; #查看主mysql的dump线程是否空闲状态,主mysql上执行
![](https://img.haomeiwen.com/i8662688/698096c6f5be01e9.png)
show slave status\G #查看slave mysql的sql线程是否已经执行完毕
![](https://img.haomeiwen.com/i8662688/268fba35ffa894a1.png)
分别在master 和slave执行 show master status; show slave status; 查看双方的数据是否已经同步完成
![](https://img.haomeiwen.com/i8662688/abb8b54eeb87cd0c.png)
然后在从库执行:stop slave IO_THREAD; stop slave;
执行 reset master; (可执行,也可以不执行。执行就是清空bin-log文件)
执行 reset slave all;
然后在主库执行:
unlock tables;
change master to master_host='192.168.209.128',master_port=33061,master_user='rep',master_password='123456',master_log_file='bin-log-mysqld5.000004',master_log_pos=120;
gtid模式,主从切换
主mysql进行锁表
flush tables with read lock;
show full processlist; #查看主mysql的dump线程是否空闲状态,主mysql上执行
show slave status\G #查看slave mysql的sql线程是否已经执行完毕
分别在master 和slave执行 show master status; show slave status; 查看双方的已经执行的gtid事务的是否一样
然后在从库执行:stop slave IO_THREAD; stop slave;
这里不要使用 reset master;让它保留已经执行过的gtid,不要清除掉。
执行 reset slave all;
然后在主库执行:
unlock tables;
change master to
master_host='192.168.209.128',master_port=33061,master_user='rep',master_password='123456',master_auto_position=1;
网友评论