mysql - mysqldump with multiple triggers -
i using mysqldump create , restore backup onto server.
one of features using lot on database triggers. appears if there more 1 trigger 1 action on database restore failing because of dependency on object (the second trigger) not yet created.
the reason seems both trigger declarations contain reference each other. executed in sequence, first of these fails.
create trigger trigger_one ... precedes trigger_two ...; [and bit further down] create trigger trigger_two ... follows trigger_one ...;
i've separated data , structure , separated structure 'just triggers' , 'everything but' following this article on percona blog, yet problem exists , i'd able automate backups , replication.
i can't reproduce problem.
i don't have clear mysql version used in article of percona mentioned, doubt 5.7 (or @ least 5.7.2).
test:
mysql> select version(); +-----------+ | version() | +-----------+ | 5.7.13 | +-----------+ 1 row in set (0.00 sec) mysql> create table `mytable` (`mycol` bool); query ok, 0 rows affected (0.00 sec) mysql> create trigger `trigger_one` before insert on `mytable` -> each row -> set new.`mycol` := 1; query ok, 0 rows affected (0.00 sec) mysql> create trigger `trigger_two` before insert on `mytable` -> each row precedes `trigger_one` -> set new.`mycol` := 2; query ok, 0 rows affected (0.00 sec)
$ mysqldump mydatabase > dump.sql
-- -- table structure table `mytable` -- drop table if exists `mytable`; /*!40101 set @saved_cs_client = @@character_set_client */; /*!40101 set character_set_client = utf8 */; create table `mytable` ( `mycol` tinyint(1) default null ) engine=innodb default charset=utf8; /*!40101 set character_set_client = @saved_cs_client */; ... delimiter ;; /*!50003 create*/ /*!50017 definer=`testuser`@`testmachine`*/ /*!50003 trigger `trigger_two` before insert on `mytable` each row set new.`mycol` := 2 */;; delimiter ; ... delimiter ;; /*!50003 create*/ /*!50017 definer=`testuser`@`testmachine`*/ /*!50003 trigger `trigger_one` before insert on `mytable` each row set new.`mycol` := 1 */;; delimiter ; ...
21.3.1 trigger syntax , examples
...
... affect trigger order, specify clause after each row indicates follows or precedes , name of existing trigger has same trigger event , action time. ...
...
Comments
Post a Comment