mysql通过触发器实现跨库表同步

插入:

DELIMITER $$
CREATE
TRIGGER inser_test 
AFTER INSERT ON test1.t1
FOR EACH ROW
BEGIN
INSERT INTO test2.t1(id) VALUES (NEW.id);
END;
$$

删除:

DELIMITER $$
CREATE
TRIGGER delete_test 
AFTER delete ON test1.t1
FOR EACH ROW
BEGIN
delete from test2.t1 where id=old.id;
END;
$$

更新:

DELIMITER $$
CREATE
TRIGGER update_test 
AFTER update ON test1.t1
FOR EACH ROW
BEGIN
UPDATE test2.t1 set id=NEW.id where id=old.id;
END;
$$

你可能感兴趣的:(linux)