创建触发器不会在 mysql 中复制

Create Trigger does not replicate in mysql

我们在主数据库中创建了一个触发器,但触发器没有显示在从数据库中。

下面是一个创建触发器的例子:

CREATE TRIGGER filter_pos_transaction_delivery_combo_details BEFORE INSERT ON `pos-transaction_delivery_combo_details`
for each row
begin
    DECLARE msg VARCHAR(200);
    SET @store_code = (SELECT value FROM `admin-settings` WHERE attribute = 'local_store_code' LIMIT 1);

    if STRCMP(new.store_code,@store_code) != 0 then
        if STRCMP( @store_code,'MAINDB') != 0 then
            set msg = "SKIPPING INSERTION: THIS DATA IS NOT FOR THIS LOCAL DB - pos-transaction_delivery_combo_details ";
            SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
        end if;
    end if;
end;

这里是cnf配置:

[mysqld]
user                        = mysql
port                        = 3306
datadir                     = /data/mysql/
pid-file                    = /data/mysql/fusion-maindb.pid
socket                      = /data/mysql/fusion-maindb.sock
log_error                   = /datalog/mysql_error_log/mysql_error.log

## Replication and Logging Settings ###
server_id                   = 11111111
log_bin                     = /datalog/rep_binlogs/maindb-bin.log
binlog_do_db                = fusion
replicate_do_db             = fusion
max_binlog_size             = 1000M
slave-skip-errors           = 1644,1007,1062,1449,1146,1062
innodb_buffer_pool_size     = 8000M
log_slave_updates           = 1
skip-external-locking
sync_binlog                 = 1
slave_net_timeout           = 60
innodb_lock_wait_timeout    = 120
binlog_format               = STATEMENT
slave_compressed_protocol   = 1
wait_timeout                = 300
interactive_timeout         = 300

检查您的二进制日志格式:

当使用基于语句的复制时,从属上的触发器由在主控上执行的语句执行(并复制到从属)。

当使用基于行的复制时,由于在主服务器上运行然后复制到从服务器的语句,触发器不会在从服务器上执行。相反,当使用基于行的复制时,在主服务器上执行触发器引起的更改将应用​​于从服务器。