环境配置:
2.6 主
2.7 从
先在主上创建一个库模拟实验环境
查看从的状态: 这里是从同步到的位置
或者查看master-info文件:cd /var/lib/mysql/
关闭slave, 模拟slave无法同步的状态
到master上新建表
查看bin-log位置
把从库没有的数据备份出来
mysqlbinlog /var/lib/mysql/mysql-bin.000003 --start-position='367' --stop-position='698' > /root/1233.sql
把数据copy到从上
scp /root/1233.sql @192.168.2.7:/root/1233.sql
把从切换为主
2.7从→主
首先重置我们从服务器上的所有配置
mysql
MariaDB [(none)]> stop slave; #关闭从复制
Query OK, 0 rows affected, 1 warning (0.00 sec)
MariaDB [(none)]> reset master; #重置主
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> reset slave all; #重置从
Query OK, 0 rows affected (0.00 sec)
#从新授权
MariaDB [(none)]> grant replication slave on *.* to 'slave'@'192.168.59.143' identified by '123';
Query OK, 0 rows affected (0.00 sec)
#刷新权限
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql
use wg;
source /root/1233.sql
查看一下数据有没有导入成功
ok