export DB or tables with triggers?

2,057 views
Skip to first unread message

pweil

unread,
Nov 22, 2011, 11:36:16 AM11/22/11
to seque...@googlegroups.com
Doing an SQL export/dump leaves out table triggers. Is there any way to include triggers in an export or dump?

Rowan Beentje

unread,
Nov 22, 2011, 11:46:07 AM11/22/11
to seque...@googlegroups.com
Hi pweil,

The SQL export should include triggers - I've just confirmed that with a test export. If you open up the exported SQL file, can you confirm you're not seeing any block like:

DELIMITER ;;
/*!50003 SET SESSION SQL_MODE="" */;;
/*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `foo` ... */;;
DELIMITER ;
/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;

Thanks,
Rowan


On 22 Nov 2011, at 16:36, pweil wrote:

> Doing an SQL export/dump leaves out table triggers. Is there any way to include triggers in an export or dump?
>

> --
> You received this message because you are subscribed to the Google Groups "Sequel Pro" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/sequel-pro/-/WQ9r7b2AcgAJ.
> To post to this group, send email to seque...@googlegroups.com.
> To unsubscribe from this group, send email to sequel-pro+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sequel-pro?hl=en.

pweil

unread,
Nov 22, 2011, 7:39:29 PM11/22/11
to Sequel Pro
Yes, it is in there. I hadn't examined it; I just tried to import it,
and the trigger was missing. What's the explanation for it's being
commented out in the dump? (I see other stuff that is also commented
out, such as

/*!40000 ALTER TABLE `projects_users` DISABLE KEYS */;

Thanks.

On Nov 22, 10:46 am, Rowan Beentje <ro...@beent.je> wrote:
> Hi pweil,
>
> The SQL export should include triggers - I've just confirmed that with a test export.  If you open up the exported SQL file, can you confirm you're not seeing any block like:
>
> DELIMITER ;;
> /*!50003 SET SESSION SQL_MODE="" */;;
> /*!50003 CREATE */ /*!50017 DEFINER=`root`@`localhost` */ /*!50003 TRIGGER `foo` ... */;;
> DELIMITER ;
> /*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;
>
> Thanks,
> Rowan
>
> On 22 Nov 2011, at 16:36, pweil wrote:
>
>
>
>
>
>
>
> > Doing an SQL export/dump leaves out table triggers. Is there any way to include triggers in an export or dump?
>
> > --
> > You received this message because you are subscribed to the Google Groups "Sequel Pro" group.

> > To view this discussion on the web visithttps://groups.google.com/d/msg/sequel-pro/-/WQ9r7b2AcgAJ.

Rowan Beentje

unread,
Nov 23, 2011, 4:09:15 AM11/23/11
to seque...@googlegroups.com
Hi pweil,

That specific comment syntax - with the exclamation mark and number - is a special MySQL comment syntax which means "only execute this on MySQL x.y.z or later". So the trigger statements check for MySQL 5.0.3, which is the first version supporting triggers, and the DISABLE KEYS statement requires 4.0.0.

This allows exports to be transferred across MySQL versions without throwing errors.

Were you importing to a MySQL 4 server? If not, we'll have to check this further :)

Rowan

Jean-Yves

unread,
Nov 30, 2011, 11:47:55 AM11/30/11
to Sequel Pro
Just to add some potentially related info to this thread, I had some
issues wirth triggers not surviving the round trip out of and back
into MySQL via SequelPro.

In the end, I resorted to recreating the disappearing triggers in
MySQL Workbench, dumping the DB form there and only then reimporting
into SequelPro. After which point all seems to have resolved itself -
I can export and reimport my db (which has ~20 triggers, 5 stored
functions and ~80 stored procedures) all without problem.

Mind you, I don't think that I've actually changed any triggers since
then (stored procs and functions certainly, on a daily basis, and this
was about 3 weeks ago).

So, it's just possible that pweil is getting the same problem I had.

Unfortunately, I cannot supply the code as it is commercially
sensitive and my client would not appreciate me sharing it with the
world ;-)

SP 0.9.9.1, MySQL 5.1.57-log (from MacPorts), OS X 10.6.8

Rowan Beentje

unread,
Nov 30, 2011, 11:52:48 AM11/30/11
to seque...@googlegroups.com
Hi Jean-Yves,

That's very interesting information. So you initially created the triggers in Sequel Pro, after which they couldn't be exported and imported correctly; you then recreated them in MySQL Workbench, exported from there, re-imported, and now Sequel Pro both exports and imports them correctly as well?

I appreciate the commercial sensitivity, but it would be great if you still have one of the old (broken) SQL dumps, could check it for a trigger statement, find the same statement in the working dumps, and let us know the differences :)

If not, I'll add this as a bug to our tracker for investigation.

Rowan

pweil

unread,
Nov 30, 2011, 4:09:08 PM11/30/11
to Sequel Pro
Sorry for not following up on this. No, I was importing from and to a
MySQL 5x server.

Jean-Yves

unread,
Dec 2, 2011, 9:53:29 AM12/2/11
to Sequel Pro
Hi Rowan,

I'll see what I can dig out. It should all be in SVN so I will have
the code. Actually from memory the triggers that kept disappearing
were quite simple, I think they just updated a DATETIME column, so
that code won't be sensitive. I probably can't get anything out to
you until next week though, as am in the middle of major deploy to our
staging server.

One thing I noticed:
Just today I wanted another of these simple update timestamp before
insert triggers for a new table. I went to the def of an existing one
and just copied the code, then cancelled out of the dialogue.

I went to the new table, clicked + to add the trigger, gave it a new
name and pasted the trigger code.

The new trigger was created, but the one I had copied the code from
was gone!

Now I don't kow whether it was really gone or whether SP just was not
displaying it (I forgot to go to Workbench to check). I simply
recreated it and all was fine.

Not sure what this proves, if anything, but maybe something to try
yourself and it may be connected?

UPDATE: I can confirm that I can recreate this. I think it is because
if you open another trigger first, the trigger details are stored in
memory so when you go to create the new one all is in place (name +
code). When you change the name, I guess what the underlying code is
doing is droppiung the trigger with the old stored name and replacing
it with the one with the new stored name, since it is correctly
assuming that as MySQL can only have 1 trigger of each type per table,
what you really want is a drop and create, not a create (ie it is not
checking what table the trigger is being based on).

Hope this helps to some extent.

Jean-Yves

unread,
Dec 6, 2011, 7:19:51 AM12/6/11
to Sequel Pro
Rowan,

Here's a sample of the very basic triggers that were causing the
issues:

DELIMITER ;;

CREATE DEFINER=`mysqladmin`@`localhost` TRIGGER
`feed_snapshot_before_insert` BEFORE INSERT ON `feed_snapshot` FOR
EACH ROW BEGIN
-- Set the creation date
SET NEW.created = NOW();
END ;;
DELIMITER ;

However, I doubt whether the actual trigger code is the problem, as it
really is basic.

Is it possible that the not-saving of triggers may have been as a
result of the bug I mention in the previous post, and that Sequel
Pro's internal triggers collection was simply out of synch somehow
when exporting?

Brock

unread,
May 19, 2012, 10:57:29 AM5/19/12
to seque...@googlegroups.com
I was running into this same issue with 0.9.9.1 and I am not sure if this issue has been resolved in the nightly builds.

The database that I was working on was original setup in workbench and the original triggers were working. Using Sequel Pro I add some additional triggers on other tables by opening the existing triggers and copying the code then creating a new trigger and pasting in the code. I also experienced the trigger that the code was copied from was deleted after creating the new trigger on a different table. I would then recreated the deleted trigger and things would seem to work. Later after an export and import I noticed that the new triggers I had create in SP had disappeared. I looked at the SQL dump and it looks like the triggers were not dumped.

I believe that the bug was caused by the act of trying to copy the existing triggers and pasting them into a new table. I too was copying a very simple trigger that added a timestamp to a column. After reading Jean-Yves comments and his connection to it relating to the copy and paste action I tried a new approach. I restarted SP and created the triggers from scratch never looking at or selecting the existing triggers.

This seemed to work as the triggers now survive an export and import. So I believe that 0.9.9.1 has a bug relating to selecting a trigger then closing and adding a new trigger elsewhere ... I think the gui changes 
where you are editing but the application actually is affecting the original trigger that was copied from.
Reply all
Reply to author
Forward
0 new messages