主从对调:
1、对调之前:
192.168.4.9作为主库,192.168.4.10作为从库
2、对调之后:
192.168.4.10作为主库,192.168.4.9作为从库
4、具体操作如下:
SDB操作:
(1)在SDB停掉slave
mysql> stop slave;
Query OK, 0 rows affected (0.04 sec)
(2)清空主从信息(主从都需执行)
mysql> reset slave all;
(3)查看从库状态是否为空
mysql> show slave status;
Empty set (0.00 sec)
(4)SDB上创建用来主从同步的slave用户
mysql> grant replication slave on *.* to 'slave'@'192.168.4.10' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
(5)SDB上查看主状态
查看master状态
mysql> show master status;
+------------------+----------+-----------------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+-----------------------+------------------+-------------------+
| mysql-bin.000001 | 121 | include_database_name | mysql | |
+------------------+----------+-----------------------+------------------+-------------------+
1 row in set (0.00 sec)
UDB操作:
(1)UDB从库建议和SDB的主从关系
mysql> change master to master_host='192.168.4.10',master_user='slave',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=401;
Query OK, 0 rows affected, 2 warnings (0.04 sec)
(2)启动slave
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
(3)查看同步状态
mysql> show slave status\G;