关于mysql主从复制的过滤机制的测试

//关于mysql主从复制的过滤机制的测试
# by coco
# 18695857601

slave 状态显示区别:

Replicate_Do_DB: db2
Replicate_Do_Table: db2.%     
Replicate_Wild_Do_Table: db2.%


my.cnf 参数配置区别:
replicate-do-db=db2
replicate-do-table=db2.%
replicate-wild-do-table=db2.%

具体示例如下:
1. 主库上创建2个数据库:db1,db2  从库上第一次配置文件参数为:replicate-do-db=db2
   结论: db1,db2中插入的数据,都同步过来啦。如下:

主库操作

mysql> create database db1;
Query OK, 1 row affected (0.03 sec)
mysql> 
mysql> create database db2;
Query OK, 1 row affected (0.00 sec)
mysql> 
mysql> use db1;
Database changed
mysql> 
mysql> create table t1 (a int,b int);
Query OK, 0 rows affected (0.06 sec)
mysql> 
mysql> select * from t1;
Empty set (0.00 sec)

mysql> 
mysql> use db2;
Database changed
mysql> 
mysql> create table t2(no int,name varchar(2));
Query OK, 0 rows affected (0.02 sec)
mysql> 
mysql> insert into db1.t1 values(1,2);
Query OK, 1 row affected (0.00 sec)
mysql> 
mysql> insert into db1.t1 values(1,3);
Query OK, 1 row affected (0.02 sec)
mysql> 
mysql> insert into db1.t1 values(1,5);
Query OK, 1 row affected (0.00 sec)
mysql> 
mysql> select * from db1.t1;
+------+------+
| a    | b    |
+------+------+
|    1 |    2 |
|    1 |    3 |
|    1 |    5 |
+------+------+
3 rows in set (0.00 sec)

db2插入的数据:
mysql> insert into db2.t2 values(1,'he');
Query OK, 1 row affected (0.00 sec)
mysql> 
mysql> select * from db2.t2;
+------+------+
| no   | name |
+------+------+
|    1 | he   |
+------+------+
1 row in set (0.00 sec)

从库查询结果:
mysql> select * from db1.t1;
+------+------+
| a    | b    |
+------+------+
|    1 |    2 |
|    1 |    3 |
|    1 |    5 |
+------+------+
3 rows in set (0.00 sec)
mysql> select * from db2.t2;
+------+------+
| no   | name |
+------+------+
|    1 | he   |
+------+------+
1 row in set (0.00 sec)

2. 主库不变,从库采用:replicate-do-table=db2.%
    结论:夸库同步的数据没有同步过来。db2中主库插入的数据,从库上没有同步过来。

主库插入:
mysql> insert into db2.t2 values(1,'hh');
Query OK, 1 row affected (0.04 sec)

mysql> 
mysql> insert into db2.t2 values(1,'gg');
Query OK, 1 row affected (0.00 sec)

mysql> 
mysql> insert into db2.t2 values(1,'cd');
Query OK, 1 row affected (0.00 sec)

从库查询结果:
mysql> select * from db2.t2;
+------+------+
| no   | name |
+------+------+
|    1 | he   |
+------+------+
1 row in set (0.03 sec)

mysql> select * from db1.t1;
+------+------+
| a    | b    |
+------+------+
|    1 |    2 |
|    1 |    3 |
|    1 |    5 |
+------+------+
3 rows in set (0.03 sec)

3. 主库不变,从库配置采用:replicate-wild-do-table=db2.% 
    结论:主库插入的数据,db2同步了过来。

主库插入数据:
mysql> insert into db2.t2 values(2,'ss');
Query OK, 1 row affected (0.00 sec)

mysql> 
mysql> insert into db2.t2 values(2,'aa');
Query OK, 1 row affected (0.01 sec)

mysql> 
mysql> insert into db2.t2 values(2,'cc');
Query OK, 1 row affected (0.00 sec)

从库显示结果:
mysql> select * from db1.t1;
+------+------+
| a    | b    |
+------+------+
|    1 |    2 |
|    1 |    3 |
|    1 |    5 |
+------+------+
3 rows in set (0.00 sec)

mysql> select * from db2.t2;
+------+------+
| no   | name |
+------+------+
|    1 | he   |
|    2 | cd   |
|    2 | ss   |
|    2 | aa   |
|    2 | cc   |
+------+------+
5 rows in set (0.00 sec)

你可能感兴趣的:(关于mysql主从复制的过滤机制的测试)