MySql触发器实现数据同步学习
Posted 凡是过往,皆为序章。
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySql触发器实现数据同步学习相关的知识,希望对你有一定的参考价值。
触发器实现:(增、删、改操作事件触发数据单向同步)
数据库触发器教程:https://www.cnblogs.com/phpper/p/7587031.html
同步代码:
DELIMITER $ DROP TRIGGER IF EXISTS insertdata; CREATE TRIGGER insertdata AFTER INSERT ON repair.user FOR EACH ROW BEGIN DECLARE s1 INT(11); DECLARE s2 VARCHAR(30); SET s1=NEW.id; SET s2=NEW.name; INSERT INTO sale.user(id,name) VALUES(s1,s2); END $ DELIMITER $ DROP TRIGGER IF EXISTS updatedata; CREATE TRIGGER updatedata AFTER UPDATE ON repair.user FOR EACH ROW BEGIN DECLARE s1 INT(11); DECLARE s2 VARCHAR(30); SET s1=OLD.id; SET s2=NEW.name; UPDATE sale.user a SET a.name=s2 WHERE a.id=s1; END $ DELIMITER $ DROP TRIGGER IF EXISTS deletedata; CREATE TRIGGER deletedata AFTER DELETE ON repair.user FOR EACH ROW BEGIN DECLARE s1 INT(11); DECLARE s2 VARCHAR(30); SET s1=OLD.id; SET s2=OLD.name; DELETE FROM sale.user WHERE id=s1; END $
以上是关于MySql触发器实现数据同步学习的主要内容,如果未能解决你的问题,请参考以下文章
mysql 触发器学习(可以将mysql数据同步到redis)
实现mysql和redis之间的触发数据同步——mysql 触发器+gearman+php.worker