20

I'm using mysqldump to replicate a database between accounts on a particular machine. Everything works just great, except when we get to our defined views. Because the dump includes a line like the following ...

/*!50013 DEFINER=`user_a`@`localhost` SQL SECURITY DEFINER */

... when loading the dump into mysql on user_b we receive an error:

ERROR 1227 (42000) at line 657: Access denied; you need the SUPER privilege for this operation

Needless to say, I don't have SUPER privilege on this mysql instance. Is there a way to convince mysqldump to dump the views in a user-agnostic way? I can't find anything in the manual on this point. Do I have to actually parse the dumpfile to replace the usernames? Or am I missing something?

4 Answers 4

27

same problem. I solved it that way:

mysqldump -uuser1 -ppassword1 database1 > backup.sql

sed '/^\/\*\!50013 DEFINER/d' backup.sql > backup_without_50013.sql

mysql -u user2 -ppassword2 -D database2 < backup_without_50013.sql

The interesting thing is the sed command which, here, removes all lines beginning with /*!50013.

Heidy

1
  • 2
    Thanks, I actually ended up doing the same thing, except using grep -v instead of sed, but the result was the same. :) Nov 26, 2008 at 12:12
12

You will need to process the backup file and change the DEFINER:

DEFINER=user_a@localhost

I like to change it to :

DEFINER=CURRENT_USER

It will then be automatically associated to the account that loads it.

2
  • 3
    thanks for the tip! I use (I need to escape the `): sed -ri s/DEFINER=`[^`]+`@`%`/DEFINER=CURRENT_USER/g file.sql
    – bbigras
    Nov 7, 2010 at 20:43
  • 2
    This! And with a little sed magic from @brunoqc it's just perfect
    – Matt
    Jan 24, 2012 at 14:14
2

The SQL SECURITY clauses determine which MySQL account to use when checking access privileges for the view (as you have probably figured out).

When you create a view you can define a couple of options for security for that view. You can read more here, but essentially by default access is restricted to the 'definer' of the view, i.e. the user who created it.

1
  • Thanks, Max. I checked it out, and it doesn't seem that tinkering with these options affects the way mysqldump produces output. If it would simply omit the DEFINER line, I would be golden. :) Sep 30, 2008 at 21:05
0

Run mysqldump with the option "--skip-triggers"

1
  • Interesting idea, but this doesn't do anything to affect the @DEFINER lines in the dump output. As long as I'm asserting a definer other than the logged-in MySQL user, I get the security error. Nov 17, 2009 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.