如果在自行安装的MySQL上无法使用trigger,可以使用下面的方法:
解决方法:
第一步,用root用户登录:mysql -u root -p
第二步,设置参数log_bin_trust_function_creators为1:set global log_bin_trust_function_creators = 1;
在AWS上面的无法使用会得到以下报错:
mysql> create trigger ins_sum before insert on account for each row set @sum = @sum + new.amount;
ERROR 1419 (HY000): You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
解决方案是新建数据库参数组:
-
导航到参数组,新建-填写名称和描述,查找log_bin_trust_function_creators 并设置为‘1’。
-
导航到数据库,选择要与数据库参数组关联的数据库实例;选择操作,然后选择修改;选择要与该数据库实例关联的参数组。