mysql 主主复制(双主复制)binlog-do-db

[root@DB ~]# grep "binlog-do-db" /etc/my.cnf 
binlog-do-db = test
[root@DB-S ~]# grep "binlog-do-db" /etc/my.cnf
binlog-do-db=test
binlog-do-db=test2

 

DB:
mysql> use test2;
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> 
DB-S:
mysql> show tables;
Empty set (0.04 sec)

mysql> CREATE TABLE `users` (
    ->   `id` int(11) NOT NULL AUTO_INCREMENT,
    ->   `name` varchar(20) NOT NULL,
    ->   `password` varchar(100) NOT NULL,
    ->   `address` varchar(200) DEFAULT NULL,
    ->   PRIMARY KEY (`id`),
    ->   UNIQUE KEY `name` (`name`)
    -> ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.06 sec)

mysql> show tables;
+-----------------+
| Tables_in_test2
+-----------------+
| users           |
+-----------------+
1 row in set (0.00 sec)
DB:
mysql> SHOW TABLES;
+-----------------+
| Tables_in_test2 |
+-----------------+
| users           |
+-----------------+
1 row in set (0.00 sec)
mysql> drop table users;
Query OK, 0 rows affected (0.00 sec)

DB-S:
mysql> show tables;
+-----------------+
| Tables_in_test2 |
+-----------------+
| users           |#因DB没指定test2,所以发生变化从库DB-S也不会变化
+-----------------+
1 row in set (0.00 sec)

  注意:my.cnf中binlog-do-db=库名,当这个库发生变化时,从库也会发生相应的变化,也就是说互为主从的两个库都要用这个参数指名相应的相做主从同步的库;并要主注如果要多个库时,同时也要有多个binlog-do-db参数

[root@DB-S ~]# grep "binlog-do-db" /etc/my.cnf
binlog-do-db=test
binlog-do-db=test2
[root@DB ~]# grep "binlog-do-db" /etc/my.cnf 
binlog-do-db = test
binlog-do-db = test2

 

posted @ 2016-07-12 10:40  bass  阅读(1206)  评论(0编辑  收藏  举报