Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use mysqldump to replicate views between accounts?

Tags:

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?

like image 448
Adam Bellaire Avatar asked Sep 30 '08 18:09

Adam Bellaire


People also ask

What is the Mysqldump program used for?

4 mysqldump — A Database Backup Program. The mysqldump client utility performs logical backups, producing a set of SQL statements that can be executed to reproduce the original database object definitions and table data. It dumps one or more MySQL databases for backup or transfer to another SQL server.

Does Mysqldump include users?

user; Knowing this, it's pretty obvious that mysqldump shouldn't do anything with users. However, if you need an answer to exporting/importing users and perms I suggest you check the following article - it helped me out.

How use Mysqldump command line?

To dump/export a MySQL database, execute the following command in the Windows command prompt: mysqldump -u username -p dbname > filename. sql . After entering that command you will be prompted for your password.


2 Answers

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

like image 151
user40237 Avatar answered Sep 26 '22 03:09

user40237


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.

like image 21
johnk Avatar answered Sep 22 '22 03:09

johnk