Migrating Ownership of Your Stored Routines, Views, and Triggers in MySQL
source link: https://www.percona.com/blog/migrating-ownership-of-your-stored-routines-views-and-triggers-in-mysql/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
“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.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK