CiviCRM defines MySQL triggers for certain tasks. When you use phpMyAdmin, mysqldump or similar to export your database to a text file, it exports your triggers as well. The format is something like this:
/*!50003 CREATE*/ /*!50017 DEFINER=`newpress`@`localhost`*/ /*!50003 TRIGGER civicrm_address_after_insert after insert ON civicrm_address FOR EACH ROW BEGIN
The issue is the DEFINER
clause. This specifies the user whose permissions are used when the trigger runs. When you import a database, it defines your triggers, but you can NOT define a trigger to run as someone other than yourself. So if the MySQL username has changed, you must fix your triggers.
You can either a) change the name of the MySQL user listed as the DEFINER, or b) remove the DEFINER portion of the clause altogether. If you don't specify a user, MySQL will default to DEFINER = CURRENT_USER
, which in this case is correct.
You can fix this with a search-and-replace in your favorite text editor. If that text editor is vim
, you can press :
and paste this command in to remove all the definer clauses:
%s:/\*\!50017.*localhost`\*/::
EDIT: Chris' regex below is good. I improved it slightly here:
perl -pi -e 's#\/\*\!5001[7|3].*?`[^\*]*\*\/##g' /path/to/mysqldump.sql