授权模式不起作用,无法授予模式触发器权限。

4

我需要给一个用户在MySQL中整个模式的TRIGGER权限,以便导入MySQL Workbench备份。

我尝试了以下方法:

grant trigger ON `schemaname`.* TO `user`@`localhost`

但是在导入时出现错误,提示用户没有权限。

ERROR 1142 (42000) at line 53: TRIGGER command denied to user 'user'@'localhost' for table 'table'

我试图给用户赋予对该表的TRIGGER权限-这可以工作,但仅限于该表,其他表仍然会出现错误。是否有方法可以为用户授予架构的触发器权限,而不必单独为每个表授予权限?
2个回答

3

From MySQL Docs

In MySQL 5.0 CREATE TRIGGER requires the SUPER privilege.

所以您需要为用户赋予SUPER权限。在导入时,会有一个类似于“Create Trigger…”的命令,它会抛出一个错误。

检查导入文件中触发器的MySQL版本和定义者值。

编辑: 对于版本5.1,请遵循MySQL文档,其中提到:

CREATE TRIGGER requires the TRIGGER privilege for the table associated with the 
trigger. The statement might also require the SUPER privilege, depending on 
the DEFINER value, as described later in this section. If binary logging is 
enabled, CREATE TRIGGER might require the SUPER privilege, as described in 
Section 19.7, “Binary Logging of Stored Programs”. (Before MySQL 5.1.6, there is 
no TRIGGER privilege and this statement requires the SUPER privilege in all cases)

The DEFINER clause determines the security context to be used when checking access
privileges at trigger activation time.

因此,您需要检查导入触发器的定义者值。它可能类似于:DEFINER = root。尝试移除定义者,然后再尝试导入。希望能够解决问题...


但是如果我授予单个表的权限,创建触发器就可以工作。难道没有其他方法可以让用户在整个数据库模式中创建触发器吗?我认为授予SUPER权限过于强大了吧?下一个问题是,如果我首先向每个单独的表授予触发器权限,我会收到“表不存在”的错误。唯一的方法是仅导出模式,导入它,授予权限并运行整个备份导入吗? - take
我正在使用mysql版本5.1.61。 - take

0

在 MySQL 文档中:

To relax the preceding conditions on function creation (that you must have the
SUPER privilege and that a function must be declared deterministic or to not
modify data), set the global log_bin_trust_function_creators system variable
to 1. By default, this variable has a value of 0, but you can change it like
this:

mysql> SET GLOBAL log_bin_trust_function_creators = 1;
You can also set this variable by using the
--log-bin-trust-function-creators=1 
option when starting the server.

设置全局变量并重新打开会话后,我能够插入触发器


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接