Unexpected problem with triggers and mysqldump

February 11, 2013
Author
Stephane Combaudon
Share this Post:

Some time ago, I had to convert all tables of a database from MyISAM to InnoDB on a new server. The plan was to take a logical dump on the master, exporting separately the schema and the data, then edit the CREATE TABLE statements to ensure all tables are created with InnoDB, and reload everything on the new server.

Quite easy, isn’t it? Of course I wanted to run a test first before performing the actions on a live system.

So let’s play with the sakila database.

mysqldump has options to export schema and data separately, let’s use them:

Just to check that everything is fine, let’s reimport the data in a new database:

What????

Let’s look around line 86:

Ok, so we’re trying to create a trigger and it fails. The error message suggests that there is already a trigger on BEFORE INSERT for this table.

That’s correct: if we look at the schema.sql file, we can see the same trigger definition.

This means that the --no-create-info option doesn’t include the CREATE TABLE statements in the output, but includes CREATE TRIGGER statements. Is it documented? Well, sort of…

If you look at the mysqldump documentation, you will see:

So the conclusion is that if you are using triggers and if you want to dump data only, you have to use --skip-triggers along with --no-create-info.

The correct way to export data is therefore:

I’m quite surprised that such an issue never came up before, it may be an indication that using triggers is far from being a common practice with MySQL.

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved