时间:2021-07-01 10:21:17 帮助过:20人阅读
设置master2从master1同步
mysql>CHANGE MASTER TO MASTER_HOST=‘192.168.1.112‘,MASTER_PORT=3306,MASTER_USER=‘backup‘,MASTER_PASSWORD=‘123456‘,MASTER_LOG_FILE=‘bin_log.00 0001‘,MASTER_LOG_POS=120; mysql>start slave; mysql> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.112 Master_User: backup Master_Port: 3306 Connect_Retry: 60 Master_Log_File: bin_log.000001 Read_Master_Log_Pos: 120 Relay_Log_File: master2-relay-bin.000002 Relay_Log_Pos: 281 Relay_Master_Log_File: bin_log.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes
如出现以下两项,则说明配置成功!
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
测试主主同步:
进入master1 mysql数据库
mysql> create database tudou1; Query OK, 1 row affected (0.02 sec) mysql> use tudou1; Database changed mysql> create table test(id int auto_increment,name varchar(10),primary key(id)); Query OK, 0 rows affected (0.01 sec) mysql> insert into test(name) values(‘a‘); Query OK, 1 row affected (0.01 sec) mysql> insert into test(name) values(‘b‘); Query OK, 1 row affected (0.00 sec) mysql> insert into test(name) values(‘c‘); Query OK, 1 row affected (0.01 sec) mysql> select * from test; +----+------+ | id | name | +----+------+ | 1 | a | | 3 | b | | 5 | c | +----+------+ 3 rows in set (0.00 sec)
进master2,查看是否有tudou1这个数据库和test表。
mysql> use tudou1; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +------------------+ | Tables_in_tudou1 | +------------------+ | test | +------------------+ 1 row in set (0.00 sec) mysql> select * from test; +----+------+ | id | name | +----+------+ | 1 | a | | 3 | b | | 5 | c | +----+------+ 3 rows in set (0.00 sec) mysql>insert into test(name) values(‘d‘);
在master1的数据库中就会发现刚在master2插入的数据也插入到数据库了。
mysql> select * from test; +----+------+ | id | name | +----+------+ | 1 | a | | 3 | b | | 5 | c | | 6 | d | +----+------+
本文是借鉴网络上的一些参考资料,本人实践操作的结果。如有不能请指出,大家共同进步。谢谢!
mysql-5.6.26 主主复制
标签:mysql主主同步