MySQL 主从同步架构中你不知道的“坑”(完结篇)
之前写出一篇文章也是关于这个主从同步架构的“坑”,具体链接如下
此篇算是接上一篇文章的后续介绍,介绍下在指定同步库的情况一些所遇到的“坑”
指定同步库情况
mysql> use testdb;
Database changed
mysql> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| test01 |
| test1 |
+------------------+
3 rows in set (0.00 sec)
mysql> insert into test1 values('zhng','man');
Query OK, 1 row affected (0.05 sec)
mysql> insert into test1 values('meimei','woman');
Query OK, 1 row affected (0.04 sec)
mysql> select * from test1;
+--------+-------+
| id | name |
+--------+-------+
| zhang | man |
| zhng | man |
| meimei | woman |
+--------+-------+
3 rows in set (0.00 sec)
从库查看
mysql> use testdb;
Database changed
mysql> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| test01 |
| test1 |
+------------------+
2 rows in set (0.01 sec)
mysql> select * from test1;
+--------+-------+
| id | name |
+--------+-------+
| zhang | man |
| zhng | man |
| meimei | woman |
+--------+-------+
3 rows in set (0.01 sec)
主库配置如下
binlog-do-db = testdb
从库配置如下
replicate-wild-do-table = testdb.%
主库操作
mysql> create database testdb;
Query OK, 1 row affected (0.01 sec)
mysql> use testdb;
Database changed
mysql> create table test01 (
-> id varchar(10) not null,
-> name varchar(10) not null
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> insert into test01 values('zhang','man');
Query OK, 1 row affected (0.01 sec)
mysql> select * from testdb.test01;
+-------+------+
| id | name |
+-------+------+
| zhang | man |
+-------+------+
1 row in set (0.00 sec)
从库查看
mysql> use testdb;
Database changed
mysql> select * from test01;
+-------+------+
| id | name |
+-------+------+
| zhang | man |
+-------+------+
1 row in set (0.00 sec)
测试在不指定忽略库的情况下默认库是否会同步数据
mysql> create user testdb_user;
Query OK, 0 rows affected (0.03 sec)
mysql> select user from mysql.user;
+-------------+
| user |
+-------------+
| testdb_user |
| mysql.sys |
| root |
+-------------+
[root@mysql-s ~]# mysql -uroot -p -e "select user from mysql.user;"
Enter password:
+-----------+
| user |
+-----------+
| mysql.sys |
| root |
+-----------+
注:默认的库的数据没有被同步