Question: How can I export the database contents (including triggers) from my dev system and import the data to the live server without running into error 1449 when a trigger gets triggered?
In a recent php project I am making extensive use of mysql triggers but ran into a problem when deploying my database from dev to live system.
E.g. one of my triggers is defined as follows (output generated by using mysqldump
)
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER update_template BEFORE UPDATE ON template
FOR EACH ROW BEGIN
SET new.mod_date := now();
END */;;
DELIMITER ;
That trigger was defined on my dev system using the user root@
localhost which creates the DEFINER=root@localhost
clause in above statement.
root@localhost does not exist as a user on the live server which causes the following error when ever the trigger gets triggered (e.g. by using update templates set...
) by the live systems user
1449: The user specified as a definer('root'@'localhost') does not exist
Currently I use mysqldump --add-drop-table --user=root -p my_project > export.sql
for export and mysql -u devuser -p my_project < export.sql
for importing data.
Export/import works flawless. The error occurs only in cases when I manipulate the data via sql and a trigger gets involved.
Edit:
MySQL version is 5.5.47 (live and dev)