【问题标题】:grant trigger to schema not working向架构授予触发器不起作用
【发布时间】:2012-08-02 12:47:15
【问题描述】:

我需要授予用户对 mysql 中整个架构的 TRIGGER 权限才能导入 mysql 工作台备份。

我试过了:

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

但是导入时会出现用户没有权限的错误。

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

我尝试授予用户 TRIGGER 对表的权限 - 这有效,但当然仅适用于该表,其他表仍然出现错误。

有没有什么方法可以在不分别授予每个表的权限的情况下授予用户对架构的触发权限?

【问题讨论】:

    标签: mysql sql-grant


    【解决方案1】:

    来自MySQL Docs

    In MySQL 5.0 CREATE TRIGGER requires the SUPER privilege.
    

    所以你需要给用户超级权限。导入时,会出现“创建触发器...”之类的命令,该命令会引发错误。

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

    编辑: 对于 5.1 版,请关注 MySQL docs,上面写着:

    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 特权会因此而被压倒吗?下一个问题是,如果我首先向每个表授予触发器权限,我会收到错误“表不存在”。是唯一导出模式的唯一方法,导入它。授予权限并运行整个备份导入?
    • 我使用的是 mysql 5.1.61 版本。
    【解决方案2】:

    在 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.
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多