为什么我不能将带有触发器的 mysql 转储导入 mariadb

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

我们计划将我们的东西迁移到 swisscom 应用云中,因此需要将现有的 MySQL 转储导入 MariaDB - 到目前为止没什么大不了的...

但是一旦应该导入触发器,转储的导入就会失败。

例如我有这个单一触发器的转储:

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 ;

我这样触发导入:

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

导致此错误:

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

奇怪的是,使用 liquibase 我们能够为完全相同的用户创建触发器。那么通过 mysql CLI 导入触发器需要什么特殊权限?

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

您看到此消息是因为 Swisscom App Cloud 中的 MariaDB 不提供 SUPER 权限,因此您无法以不同的用户身份设置触发器或查看 运行 — 只有具有SUPER 可以做到。

请参阅 Using MySQL triggers and views in Amazon RDS 了解 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