Where the open source database community meets: Use code PERCONA75 and secure your spot for Percona Live.  Register

Migrating Ownership of Your Stored Routines, Views, and Triggers in MySQL

July 7, 2021
Author
Sveta Smirnova
Share this Post:

Migrating Ownership MySQL“It would be nice to have an option, that would allow to suppress the DEFINER statement in the CREATE VIEW statements generated by mysqldump. This would help when transferring data structures between databases with different security models.”

TLDR;

Use mysqlpump with option --skip-definer instead of mysqldump.

The Story

This was requested as MySQL Bug #24680 on Nov 29, 2006. This feature request got large Community support. Even if we cannot see the number of people who voted for this request, the number of comments is impressive.

The request is very reasonable: mysqldump is widely used during application development and it is a very common practice to migrate database structure between developers’ machines and to the production servers.

Imagine a situation where developer Sveta creates a database and adds few objects with DEFINER clauses there. We will use only one for this post but in reality, she can have dozens.

Once you create a view default DEFINER is the user who created this view:

And this causes issues when another user tries to import such a view into a different server:

Here is the content of line 61:

So this is a CREATE VIEW operation that failed during import.

Unfortunately, mysqldump still does not have an option that allows migrating definers.

But since August 2015 and MySQL 5.7.8 we have a solution that, unfortunately, was overlooked in favor of the famous tool mysqldump.

Version 5.7.8 and all which created after it, come with a new dump tool: mysqlpump that has the option --skip-definer and allows to migrate database objects without any issue:

Note that mysqlpumpautomatically adds CREATE DATABASE into the dump and full path to the database objects. E.g. CREATE ALGORITHM=UNDEFINED VIEW `definers`.`large_tables` AS select Therefore this method cannot be used to migrate view, routine, or trigger definitions between different databases on the same server.

For more information about mysqlpump and why you should switch to this tool from mysqldump read this blog post, The mysqlpump Utility.

Percona Distribution for MySQL is the most complete, stable, scalable, and secure, open-source MySQL solution available, delivering enterprise-grade database environments for your most critical business applications… and it’s free to use!

Download Percona Distribution for MySQL Today

0 0 votes
Article Rating
Subscribe
Notify of
guest

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Timur Solodovnikov
Timur Solodovnikov
4 years ago

What about migration from user A to user B?

what are caveats of doing this: update mysql.proc set defer = ‘user B’ where defer = ‘user A’;
?

lefred
lefred
4 years ago

Hi Sveta,

thank you for blogging about this problematic with mysqldump. I replied with another post using the same example but with MySQL Shell that must be preferred to mysqlpump. see: https://blogs.oracle.com/mysql/migrate-ownership-of-your-stored-routines%2c-views-and-triggers-for-mysql-in-2021

cheers,

lefred
lefred
4 years ago
Reply to  Sveta Smirnova

No as single file is not compatible with parallel load… however you can create a nice single zip (or tar, thx, …) file containing all that 😉

Francisco Miguel Biete Banon
Francisco Miguel Biete Banon
4 years ago
Reply to  lefred

MySQL Shell is definitely better, but one thing I’m struggling to achieve is how to dump the DDL of all the routines, excluding the DDL of my tables… excludeTables should be able to accept wildcards or at least have the option for “all”

mysqlpump is lacking the skip-lock-tables options to play nice with PXC in strict mode and for some reason, even when excluding the tables I keep getting ALTER TABLE for the indexes and USE schema…

Far
Enough.

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