上一篇:MySQL 主从同步架构中你不知道的“坑”(上)
此篇算是接上一篇文章的后续介绍,介绍下在指定同步库的情况一些所遇到的“坑”
指定同步库情况
1、binlog_format= ROW 模式
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)
2、binlog_format= STATEMENT 模式
主库配置如下
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 |
+-----------+
注:默认的库的数据没有被同步
点击 –> 民工哥技术之路 关注微信公众号,对话框回复关键字:1024 可以获取一份最新整理的 2048G 技术干货:包括系统运维、数据库、redis、MogoDB、电子书、Java 基础课程、Java 实战项目、架构师综合教程、架构师实战项目、大数据、Docker 容器、ELK Stack、机器学习、BAT 面试精讲视频等。