mysql主备--触发器trigger

版权声明:原创文章,转载请注明出处。 https://blog.csdn.net/weixin_40559167/article/details/82906028

环境:mysql主备
主库上没有触发器,备库上有触发器。主库上执行一条更新语句:

[root@hzdbtest ~]# mysql
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 524
Server version: 5.6.19-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> update oc_coupon_info set create_time='' where  zid=365108;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

结果备库的触发器没有被触发。
查看主库的binlog日志,看看语句执行情况:

[root@test-DBmaster-172-18-19-44 mysql]# mysqlbinlog --no-defaults mysql-bin.017994 > mysql-bin-017994_1.txt
[root@test-DBmaster-172-18-19-44 mysql]# vi mysql-bin-017994_1.txt
#180930  9:22:19 server id 43  end_log_pos 53274831 CRC32 0xf008e0da    Table_map: `ordercenter`.`oc_coupon_info` mapped to number 6191
# at 53274831
#180930  9:22:19 server id 43  end_log_pos 53275355 CRC32 0xca1150e3    Update_rows: table id 6191 flags: STMT_END_F

BINLOG '
SyWwWxMrAAAAewAAAM/oLAMAAC8YAAAAAAEAC29yZGVyY2VudGVyAA5vY19jb3Vwb25faW5mbwAW
Aw8PDw8P9vb2Aw8PDw8PDw8DAw8PDyRgAIcAhwCHAIcAEgASABIAPAA8ACwBPAA8ADwAlgCHAIcA
hwD+/z/a4Ajw
SyWwWx8rAAAADAIAANvqLAMAAC8YAAAAAAEAAgAW////////AADENJIFACBmMGZmZWZkNDljNzc0
MThlOGJkN2RiNWM2NjhkYzIzZg5DVDE4MDkyODEwMDAwNw5BQzE4MDkyODEwMDAwNw5DUDE4MDky
OTEwMDA1Mw5NSTE4MDQyNzcwMDI0NoAAAAAAAAAPgAAAAAAAAA+AAAAAAAAAFAEAAAATMjAxOC0w
OS0yOCAwMDowMDowMhMyMDE4LTEwLTI4IDIzOjU5OjU5AAAQNDQ5NzQ3MTYwMDA0MDAwMRMyMDE4
LTA5LTI5IDE1OjM2OjA2AAZTSTIwMDMBAAAAABIxMDA5MzA4LTEzNzg1NDQ4LTECbGQAAMQ0kgUA
IGYwZmZlZmQ0OWM3NzQxOGU4YmQ3ZGI1YzY2OGRjMjNmDkNUMTgwOTI4MTAwMDA3DkFDMTgwOTI4
MTAwMDA3DkNQMTgwOTI5MTAwMDUzDk1JMTgwNDI3NzAwMjQ2gAAAAAAAAA+AAAAAAAAAD4AAAAAA
AAAUAQAAABMyMDE4LTA5LTI4IDAwOjAwOjAyEzIwMTgtMTAtMjggMjM6NTk6NTkAABA0NDk3NDcx
NjAwMDQwMDAxEzIwMTgtMDktMjkgMTU6MzY6MDMABlNJMjAwMwEAAAAAEjEwMDkzMDgtMTM3ODU0
NDgtMQJsZONQEco=
'/*!*/;
# at 53275355


查看主库binlog模式:

mysql> show variables like 'binlog_format';
+---------------+-----------+
| Variable_name | Value     |
+---------------+-----------+
| binlog_format | MIXED     |
+---------------+-----------+
1 row in set (0.00 sec)


可以看到该语句以row格式的binlog被记录,并在备库上执行。这样备库触发器无法被触发。

修改binlog格式:

mysql> SET global binlog_format = 'STATEMENT';
Query OK, 0 rows affected (0.00 sec)

主库再次执行相同的语句后查看binlog:

[root@test-DBmaster-172-18-19-44 mysql]# mysqlbinlog --no-defaults mysql-bin.017994 > mysql-bin-017994_2.txt
[root@test-DBmaster-172-18-19-44 mysql]# vi mysql-bin-017994_2.txt
#180930  9:41:35 server id 43  end_log_pos 53530613 CRC32 0xec8483aa    Query   thread_id=59562894      exec_time=0     error_code=0
use `ordercenter`/*!*/;
SET TIMESTAMP=1538271695/*!*/;
update oc_coupon_info set create_time='3' where  zid=365108

此时语句被完整还原出来,备库的触发器被触发。

修改主库的配置文件,将binglog格式修改为statement,防止下次重启的时候变回mixed。

猜你喜欢

转载自blog.csdn.net/weixin_40559167/article/details/82906028