MySQL5.6参数binlog-do-db和log-slave-updates跨库同步注意事项

MySQL5.6.20上在master主库配置文件/etc/my.cnf里指定数据库同步到slave从库上使用参数binlog-do-db log-slave-updates 注意事项:

一. master主库上binlog-format = MIXED为混合模式时

mysql master主库:/etc/my.cnf 当binlog-format = MIXED 位混合模式时:
1.1配置文件参数:

[[email protected] 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 [email protected]‘%‘ 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 [email protected]‘%‘ 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 模式,主要参数如下:

[[email protected] 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> 

同步完成

原文地址:http://blog.51cto.com/wujianwei/2063450

时间: 2024-11-01 15:47:48

MySQL5.6参数binlog-do-db和log-slave-updates跨库同步注意事项的相关文章

重大发现Discuz DB层跨库映射关系表名前缀BUG

场景: 在Discuz中创建Table模型,但该Table所在库与Discuz不在同一个库. Discuz好像是在3之后提供跨库映射的机制. 映射没问题,主要是发现表名前缀没有相应的映射过来.当然,其实也不算bug.因为他只考虑discuz自己的系统,一般来说,表名前缀是相同的. 在db驱动类里,db_driver_mysql(i): function table_name中 if(!empty($this->config[$id]['tablepre'])){ $this->tablepre

Replicate_Do_DB 参数发现跨库操作时从库数据不更新

问题:使用复制是设置  Replicate_Do_DB 参数发现跨库操作时从库数据不更新 1 设置从库的 replicate_do_db = test 2 主库的sql语句是跨库的insert    在test7 上插入数据到test.a 的表上. use test7; 3 主库数据更新后查看从库信息发现数据并没有插入 4 原因是mysql 在执行sql前检查的当前默认库,所以跨库的sql语句不会被执行. 解决方案: 1 使用参数   replicate-wild-ignore-table =t

mysql5.6加载percona版audit.log插件性能损耗压测

由于mysql5.6社区版没有企业版特有的audit审计插件,最近需要对生产的mysql数据库增加审计功能,在考虑了percona.maridb和macfee3个版本的audit,最终选择了较为熟悉的percona版. 这里注意下,最好采用同一子版本的PXC的audit_log.so文件,即下载PXC的二进制包文件并直接copy其内置的audit_log.so插件即可. 启用了audit审计功能,对数据库的性能存在一定的损耗,具体是多少,需要通过测试验证.在虚拟机上做了一个测试如下: 测试虚拟机

mysql-5.7.17 binlog查询

因为有的时候会出现,突然哪个字段或者表格之类被删除,我们要了解到底什么内容,什么时候,是谁删的,那我们就可以从binlog日志中查找到你需要的内容 1.binlog binlog就是二进制日志,它记录了数据库上的所有改变,并以二进制的形式保存在磁盘中: 它可以用来查看数据库的变更历史.数据库增量备份和恢复.MySQL的复制(主从数据库的复制). 因为每一条被修改数据的sql都会记录在binlog中. 2.查看与配置binlog格式 (1)查看binlog_format mysql> show v

修改MongoDb的 DB 和 Log 存储路径 (Windows)-摘自网络

Create a file called mongod.cfg in MongoDB folder if you dont have it. In my case: C:\Users\ivanbtrujillo\MongoDB Then, edit mongod.cfg with notepad and add a line with the following (our custom dbpath): dbpath=C:\Users\ivanbtrujillo\MongoDB\data\db

MySQL5.7参数log_timestamps

最近测试MySQL 5.7.21  Community Server这个版本的MySQL数据库时,发现其错误日志的时间跟系统当前时间不一致,后面检查发现日期时间格式都是UTC时间,查了一下相关资料,原来在MySQL 5.7.2 之后日志文件里面的时间戳从默认的本地系统时区改为了UTC格式.MySQL 5.7.2多了一个参数log_timestamps ,这个参数主要是控制错误日志.慢查询日志等日志中的显示时间.但它不会影响查询日志和慢日志写到表 (mysql.general_log, mysql

mysql5.7 参数记录 (持续更新)

sync_binlog 控制数据库的binlog刷到磁盘 默认sync_binlog=1,表示每次事务提交,MySQL都会把binlog刷下去,是最安全但是性能损耗最大的设置. sync_binlog=100或者是0.牺牲一定的一致性,可以获得更高的并发和性能. innodb_flush_log_at_trx_commit 控制log_buffer刷到磁盘   0  每次提交事务log_buffer不写入log_file  1 每次提交事务log_buffer写入log_file,默认配置  2

Windows下Mysql5.7开启binlog步骤及注意事项

1.查看是否开启了binlog:show binary logs; 默认情况下是不开启的. 2.开启binlog:修改mysql的配置文件my.ini.添加如下配置: 该文件默认不允许修改,需要右键"管理员取得所有权"之后才能保存修改. 另外,需要注意的是图中的my.ini位于:C:\ProgramData\MySQL\MySQL Server 5.7,而不是位于:C:\Program Files\MySQL\MySQL Server 5.7.看图: 3.重启mysql服务.如图: 4

基于mysql5.6版本的主从库同步

系统:centos6.4 mysql版本:5.6.17 主库:192.168.31.111 从库:192.168.31.235 主库操作: 1.配置my.cnf文件开启二进制日志 log_bin = on server_id = 1 2.建立用于同步数据库的账号rep grant replication slave on *.* to 'rep'@'192.168.31.%' identified by 'redhat'; select user,host,password from mysql