MySQL5.6參數binlog-do-db和log-slave-updates跨庫同步註意事項
一. master主庫上binlog-format = MIXED為混合模式時
mysql master主庫:/etc/my.cnf 當binlog-format = MIXED 位混合模式時:
1.1配置文件參數:
[root@cacti etc]# egrep "binlog-format|server-id|log-bin|binlog-do-db|log-slave-updates" /etc/my.cnf binlog-format = MIXED server-id = 1131053306 log-bin = /data/mysql/binlog/mysql-bin.log binlog-do-db=ranzhidb log-slave-updates=1
1.2登陸主庫master,切入到ranzhidb庫操作
mysql> use ranzhidb; 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> insert into droa_attend (id,account,date,status) values (‘14‘,‘yuyu‘,‘2018-01-20‘,‘rest‘); Query OK, 1 row affected, 10 warnings (0.00 sec) mysql> select * from droa_attend ; +----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+ | id | account | date | signIn | signOut | status | ip | device | client | manualIn | manualOut | reason | desc | reviewStatus | reviewedBy | reviewedDate | +----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+ | 9 | xiaowang | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 | | 10 | xiaowu | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 | | 11 | wangwu | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 | | 12 | zhangsan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 | | 13 | lisan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 | | 14 | yuyu | 2018-01-20 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 | +----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+ 14 rows in set (0.00 sec)
1.3在從庫slave上查看:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | ranzhidb | +--------------------+ mysql> select * from ranzhidb.droa_attend; +----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+ | id | account | date | signIn | signOut | status | ip | device | client | manualIn | manualOut | reason | desc | reviewStatus | reviewedBy | reviewedDate | +----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+ | 9 | xiaowang | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 | | 11 | wangwu | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 | | 12 | zhangsan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 | | 13 | lisan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 | | 14 | yuyu | 2018-01-20 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 | +----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+ 13 rows in set (0.00 sec)
同步成功
1.4登陸master主庫進行跨庫操作
但是登陸master主庫進行跨庫操作的時候,在master主庫ranzhidb.droa_attend表裏面插入一條記錄,但是在master上插入的記錄沒有同步到slave上
演示如下:
mysql> use itop;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| itop |
+------------+
1 row in set (0.00 sec)
mysql> insert into ranzhidb.droa_attend (id,account,date,status) values (‘16‘,‘wenwen‘,‘2018-01-18‘,‘rest‘);
Query OK, 1 row affected, 10 warnings (0.00 sec)
mysql> select * from ranzhidb.droa_attend;
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
| id | account | date | signIn | signOut | status | ip | device | client | manualIn | manualOut | reason | desc | reviewStatus | reviewedBy | reviewedDate |
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
| 9 | xiaowang | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 10 | xiaowu | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 11 | wangwu | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 12 | zhangsan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 13 | lisan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 14 | yuyu | 2018-01-20 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 15 | fangfang | 2018-01-18 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 16 | wenwen | 2018-01-18 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
16 rows in set (0.00 sec)
但是登陸slave上查看,id是16的記錄沒有同步到slave上
mysql> select * from ranzhidb.droa_attend;
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
| id | account | date | signIn | signOut | status | ip | device | client | manualIn | manualOut | reason | desc | reviewStatus | reviewedBy | reviewedDate |
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
| 9 | xiaowang | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 11 | wangwu | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 12 | zhangsan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 13 | lisan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 14 | yuyu | 2018-01-20 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 15 | fangfang | 2018-01-18 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
14 rows in set (0.00 sec)
同時在master上跨庫操作給同步的數據庫ranzhidb創建管理用戶時,master上創建的用戶是不能同步到slave 上的。
但是在master上切入到ranzhidb庫,給庫ranzhidb創建管理用戶後,創建的用戶是可以同步到slave 上的
演示:
master上操作:
mysql> use itop;
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>
mysql>
mysql> grant all on ranzhidb.* to txtuser01@‘%‘ identified by ‘test#558996‘;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
slave上操作:
mysql> select user,host from mysql.user;
+------------+-----------+
| user | host |
+------------+-----------+
| testuser03 | % |
| testuser04 | % |
| root | 127.0.0.1 |
| root | localhost |
+------------+-----------+
4 rows in set (0.00 sec)
txtuser01用戶沒有同步過來
master上操作:
mysql> use ranzhidb;
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> grant all on ranzhidb.* to txtuser02@‘%‘ identified by ‘test#558996‘;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
slave上查看:
mysql> select user,host from mysql.user;
+------------+-----------+
| user | host |
+------------+-----------+
| testuser03 | % |
| testuser04 | % |
| txtuser02 | % |
| root | 127.0.0.1 |
| root | localhost |
+------------+-----------+
5 rows in set (0.00 sec)
mysql>
txtuser02用戶已經同步到slave上了。
二.mysql master主庫:/etc/my.cnf 當binlog-format = MIXED 為混合模式
當master主庫配置文件/etc/my.cnf:指定binlog-format= row 模式,主要參數如下:
[root@cacti etc]# egrep "binlog-format|server-id|log-bin|binlog-do-db|log-slave-updates" /etc/my.cnf
binlog-format = row
server-id = 1131053306
log-bin = /data/mysql/binlog/mysql-bin.log
binlog-do-db=ranzhidb
log-slave-updates=1
2.1登陸MySQL主庫master上進行跨庫操作:
mysql> use itop
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> select database();
+------------+
| database() |
+------------+
| itop |
+------------+
1 row in set (0.00 sec)
mysql> insert into ranzhidb.droa_attend (id,account,date,status) values (‘15‘,‘fangfang‘,‘2018-01-18‘,‘rest‘);
Query OK, 1 row affected, 10 warnings (0.00 sec)
mysql> select * from ranzhidb.droa_attend;
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
| id | account | date | signIn | signOut | status | ip | device | client | manualIn | manualOut | reason | desc | reviewStatus | reviewedBy | reviewedDate |
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
| 9 | xiaowang | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 10 | xiaowu | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 11 | wangwu | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 12 | zhangsan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 13 | lisan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 14 | yuyu | 2018-01-20 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 15 | fangfang | 2018-01-18 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
15 rows in set (0.00 sec)
在從庫slave上查看:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| ranzhidb |
+--------------------+
mysql> select * from ranzhidb.droa_attend;
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
| id | account | date | signIn | signOut | status | ip | device | client | manualIn | manualOut | reason | desc | reviewStatus | reviewedBy | reviewedDate |
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
| 9 | xiaowang | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 11 | wangwu | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 12 | zhangsan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 13 | lisan | 2018-01-21 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 14 | yuyu | 2018-01-20 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
| 15 | fangfang | 2018-01-18 | 00:00:00 | 00:00:00 | rest | | | | 00:00:00 | 00:00:00 | | | | | 0000-00-00 00:00:00 |
+----+------------+------------+----------+----------+--------+-----------------+---------+----------+----------+-----------+--------+------+--------------+------------+---------------------+
14 rows in set (0.00 sec)
同步成功。
2.2但是此時在master上跨庫給同步的數據庫ranzhidb創建授權用戶時,授權用戶是沒有同步到slave上的。
master上操作:
mysql> select database();
+------------+
| database() |
+------------+
| itop |
+------------+
1 row in set (0.00 sec)
mysql> grant all on ranzhidb.* to ‘testuser02‘@‘%‘ identified by ‘test#558996‘;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
slave上查看:
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)
主庫上創建的用戶testuser02沒有同步到slave 上
2.3在master上切換到同步數據庫ranzhidb,創建授權用戶
mysql> use ranzhidb;
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> grant all on ranzhidb.* to ‘testuser03‘@‘%‘ identified by ‘test#558996‘;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
登陸slave上查看:
mysql> select user,host from mysql.user;
+------------+-----------+
| user | host |
+------------+-----------+
| testuser03 | % |
| root | 127.0.0.1 |
| root | localhost |
+------------+-----------+
3 rows in set (0.00 sec)
mysql>
同步完成
MySQL5.6參數binlog-do-db和log-slave-updates跨庫同步註意事項