创建触发器不会在mysql中复制
我们在主数据库中创建了一个触发器,但该触发器没有显示在从数据库中 以下是创建触发器的示例:创建触发器不会在mysql中复制,mysql,triggers,replication,Mysql,Triggers,Replication,我们在主数据库中创建了一个触发器,但该触发器没有显示在从数据库中 以下是创建触发器的示例: 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
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
检查binlog格式: 使用基于语句的复制时,从机上的触发器由在主机上执行的语句执行(并复制到从机)
使用基于行的复制时,触发器不会在从机上执行,因为这些语句在主机上运行,然后复制到从机。相反,在使用基于行的复制时,在主机上执行触发器所引起的更改将应用于从机。显示您尝试过的内容?共享您的mysql版本和配置文件my.cnf或my.ini,以及在主机上执行触发器创建语句的确切方式。我们使用的是mysql 5.6,但从机上不会显示触发器。触发器仅在主数据库中创建。是,这意味着您正在使用基于混合的复制。。。在这种情况下,由主触发器创建的命令复制到从触发器,而不是触发器本身。。所以你的数据是最新的,不用担心。。触发器未在从属数据库中运行,只有触发器在主数据库上所做的更改被复制。但是,如果我们在从属数据库中需要触发器,我们是否需要在从属数据库中手动创建触发器?是的,您需要手动创建触发器,但这将导致数据不一致。。因为主服务器在主服务器到从服务器和从服务器触发器之间复制触发器创建的命令,所以再次执行该命令。如果我们使用触发器来确认数据是否应该从从服务器复制到表上的从服务器,该怎么办?