简体   繁体   中英

why can't I import a mysql dump with triggers into mariadb

We plan to migrate our stuff into swisscom app cloud and therefore need to import existing MySQL dumps into MariaDB - so far no big deal...

But the import of the dumps fail as soon as a trigger should be imported.

eg I have a dump with this single trigger:

DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER trg_mytable_insert AFTER INSERT ON mytable FOR EACH ROW
                    BEGIN

                         INSERT INTO mytable_audit (id, fk_X)
                         SELECT a.id, a.fk_X FROM mytable a WHERE a.id = NEW.id;

                    END */;;
DELIMITER ;

I trigger the import like this:

mysql --user xxxxxxx -pxxxxxxx -h 127.0.0.1 -P 13000 CF_E7D2D18F_A20B_4FFF_89A7_XXXXXXXX < trigger.sql

causes this error:

ERROR 1227 (42000) at line 2: Access denied; you need (at least one of) the SUPER privilege(s) for this operation

The strange thing is, that with liquibase we are able to create triggers with the exact same user. So what special privileges are required to import a trigger via mysql CLI?

CREATE*/ /*!50017 DEFINER=`root`@`localhost`*

You're seeing this message because MariaDB in Swisscom App Cloud doesn't provide the SUPER privilege, and thus you cannot set up a trigger or view to run as a different user — only a user with SUPER can do that.

see Using MySQL triggers and views in Amazon RDS for a workaround with sed .

I recently had an opportunity to migrate a customer from a physical server into Amazon's RDS environment. In this particular case the customers' platform makes extensive use of MySQL triggers and views. I came across two significant issues that prevented me from following Amazon's documentation, which basically states “use mysqldump” but doesn't call out a specific method of dealing with MySQL triggers and views.

mysqldump -h hostname -u username -ppassword –single-transaction database_name | sed -e 's/\/\*[^*]*DEFINER=[^*]*\*\///' | mysql -h hostname -u username -ppassword database_name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM