MYSQL DEFINER

There are issues when you use mysqldump to dump a database and it contains DEFINER=root@x.x.x.x type references. THese are typically in the create procedures or trigger statements. The dump files contain the actual machine name even though the source .sql used to create the procedures or trigger uses CURRENT_USER syntax..

Problems arise when you reload this mysqldump on another machine and the DEFINER does not exist there. You may not have problems until you try and DUMP that database and you’ll get errors like this:.

The user specified as a definer (‘XXX’@’XXX’) does not exist

To fix this use sed to edit the DEFINER statements in the mysqldump before reloading it on another machine like this:

sed -re ‘s/DEFINER=`[^`]+`@`[^`]+`/DEFINER=CURRENT_USER/g’ mydb.dmp.sql | mysql -uroot -hdbhost -p schemaname

This uses sed with -r for extended regular expression support to convert the DEFINER = statements in the dump to CURRENT_USER which will always exist on the destination machine.

 

This entry was posted in Uncategorized. Bookmark the permalink.