參考文檔: http://www.ywnds.com/?p=6945 https://stackoverflow.com/questions/23191160/whats-the-difference-in-replicate-wild-do-table-and-replicate-do-table ...
參考文檔: http://www.ywnds.com/?p=6945 https://stackoverflow.com/questions/23191160/whats-the-difference-in-replicate-wild-do-table-and-replicate-do-table http://80888888.blog.51cto.com/2741630/1333249 http://keithlan.github.io/2015/11/02/mysql_replicate_rule/ 總共有6個過濾規則: 1 --replicate-do-db
2 --replicate-ignore-db
3 --replicate-do-table
4 --replicate-wild-do-table
5 --replicate-ignore-table
6 --replicate-wild-ignore-table
以上6個規則的前2個是庫級別的規則,後4個是表級別的規則。使用註意點: 1:庫級別的規則,只針對binlog_format='STATEMENT'或'MIXED'。
2:如果是binlog_format='ROW',不受庫級別規則限制,只受表級別規則限制。
3:表級別的規則,針對所有模式。 4:binlog_format='STATEMENT'或者'MIXED'時,記錄use 語句,此時如果使用 --replicate-do-db,則不支持跨庫修改。 如use test; update db1 set …… 這裡判斷的是use 後面的test庫,所以updte語句不執行。建議使用--replicate-wild-do-table
5:binlog_format='ROW'時,不記錄use語句。只受表級別規則的影響。只能配置後面四條規則。 測試不同模式下binlog記錄情況: 執行sql: set global binlog_format='row'; use test; update db1.t2 set name='a200' where id=105; use db1; 記錄的binlog如下:
1 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; 2 /*!40019 SET @@session.max_insert_delayed_threads=0*/; 3 /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; 4 DELIMITER /*!*/; 5 # at 4 6 #170808 0:49:08 server id 1882073306 end_log_pos 120 CRC32 0xbddf73ce Start: binlog v 4, server v 5.6.23-72.1-log created 170808 0:49:08 7 # Warning: this binlog is either in use or was not closed properly. 8 # at 120 9 #170808 0:50:16 server id 1882073306 end_log_pos 191 CRC32 0xb2586cef Query thread_id=73 exec_time=0 error_code=0 10 SET TIMESTAMP=1502124616/*!*/; 11 SET @@session.pseudo_thread_id=73/*!*/; 12 SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; 13 SET @@session.sql_mode=1073741824/*!*/; 14 SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; 15 /*!\C utf8 *//*!*/; 16 SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=33/*!*/; 17 SET @@session.lc_time_names=0/*!*/; 18 SET @@session.collation_database=DEFAULT/*!*/; 19 BEGIN 20 /*!*/; 21 # at 191 22 #170808 0:50:16 server id 1882073306 end_log_pos 245 CRC32 0xe7585ab8 Table_map: `db1`.`t2` mapped to number 395 23 # at 245 24 #170808 0:50:16 server id 1882073306 end_log_pos 365 CRC32 0x86dbbb24 Update_rows: table id 395 flags: STMT_END_F 25 ### UPDATE `db1`.`t2` 26 ### WHERE 27 ### @1=105 /* INT meta=0 nullable=0 is_null=0 */ 28 ### @2='a100' /* VARSTRING(90) meta=90 nullable=0 is_null=0 */ 29 ### @3='57747ab889255af96b48d65e505382' /* VARSTRING(90) meta=90 nullable=0 is_null=0 */ 30 ### @4='' /* VARSTRING(72) meta=72 nullable=0 is_null=0 */ 31 ### @5=NULL /* VARSTRING(72) meta=0 nullable=1 is_null=1 */ 32 ### SET 33 ### @1=105 /* INT meta=0 nullable=0 is_null=0 */ 34 ### @2='a200' /* VARSTRING(90) meta=90 nullable=0 is_null=0 */ 35 ### @3='57747ab889255af96b48d65e505382' /* VARSTRING(90) meta=90 nullable=0 is_null=0 */ 36 ### @4='' /* VARSTRING(72) meta=72 nullable=0 is_null=0 */ 37 ### @5=NULL /* VARSTRING(72) meta=0 nullable=1 is_null=1 */ 38 # at 365 39 #170808 0:50:16 server id 1882073306 end_log_pos 396 CRC32 0x99f0e5d3 Xid = 32212 40 COMMIT/*!*/;執行sql: set global binlog_format='mixed'; use test; update db1.t2 set name='a300' where id=105; use db1; 記錄的binlog如下:
1 # at 396 2 #170808 0:53:14 server id 1882073306 end_log_pos 474 CRC32 0x46f75d21 Query thread_id=74 exec_time=0 error_code=0 3 SET TIMESTAMP=1502124794/*!*/; 4 BEGIN 5 /*!*/; 6 # at 474 7 #170808 0:53:14 server id 1882073306 end_log_pos 589 CRC32 0x7193484c Query thread_id=74 exec_time=0 error_code=0 8 use `test`/*!*/; 9 SET TIMESTAMP=1502124794/*!*/; 10 update db1.t2 set name='a300' where id=105 11 /*!*/; 12 # at 589 13 #170808 0:53:14 server id 1882073306 end_log_pos 620 CRC32 0xc3e0c9e3 Xid = 32328 14 COMMIT/*!*/; 15 DELIMITER ; 16 # End of log file 17 ROLLBACK /* added by mysqlbinlog */; 18 /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; 19 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;