【问题标题】:MySQL grant ineffective?MySQL授权无效?
【发布时间】:2011-09-12 16:14:47
【问题描述】:

好吧,我很困惑。我在尝试进行更新时收到“拒绝访问”错误。有一个授权允许该用户对该表执行更新,但无论如何它都被拒绝了。是的,我尝试过“刷新属性”。

$ mysql -h DBHOST -u DBUSER -p DBNAME
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7340
Server version: 5.0.77 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> update user set lastlogin = now() where userid = 1;
ERROR 1227 (42000): Access denied; you need the SUPER privilege for this operation
mysql> show grants for DBUSER;
+--------------------------------------------------------------------------------------+
| Grants for DBUSER@%                                                                  |
+--------------------------------------------------------------------------------------+
...
| GRANT SELECT, INSERT ON `DBNAME`.`useroldpassword` TO 'DBUSER'@'%'                     |
...
| GRANT SELECT, INSERT, UPDATE ON `DBNAME`.`user` TO 'DBUSER'@'%'                      |
...
+--------------------------------------------------------------------------------------+
68 rows in set (0.01 sec)

mysql>

桌子上有一个触发器:

CREATE TRIGGER DEFINER=`DEFINER`@`localhost` UserPasswordUpdate BEFORE UPDATE ON User
FOR EACH ROW
BEGIN
    DECLARE count int;
    IF(NOT NEW.Password<=>OLD.Password) THEN
        SELECT count(*) into count FROM UserOldPassword WHERE UserID=NEW.UserID AND Password=NEW.Password;
        IF(count != 0) THEN
             INSERT INTO Unknown VALUES(1);
        END IF;
        INSERT INTO UserOldPassword(UserID,PasswordDate,Password) VALUES(NEW.UserID, NOW(), NEW.Password);
        SET NEW.LastPasswordChangeDate=NOW();
    END IF;
END

执行用户(见上文)和声明的定义者都应该有权插入到 UserOldPassword 表中:

mysql> show grants for DEFINER;
+---------------------------------------------------------------------------------+
| Grants for DEFINER@%                                                            |
+---------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'DEFINER'@'%' IDENTIFIED BY PASSWORD '...'                |
| GRANT ALL PRIVILEGES ON `DBNAME`.* TO 'DEFINER'@'%'                             |
+---------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> show grants for DEFINER@localhost;
+-----------------------------------------------------------------------------------------+
| Grants for DEFINER@localhost                                                            |
+-----------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'DEFINER'@'localhost' IDENTIFIED BY PASSWORD '...'                |
| GRANT ALL PRIVILEGES ON `DBNAME`.* TO 'DEFINER'@'localhost'                             |
+-----------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

【问题讨论】:

  • 那张桌子上有触发器吗?
  • 已更新以包含触发器信息。

标签: mysql sql sql-update access-denied sql-grant


【解决方案1】:

试试:

GRANT SUPER ON `DBNAME`.`user` TO 'DBUSER'@'%'

您可能在桌子上有一个触发器,这就是它不起作用的原因。

【讨论】:

  • 编辑了文本以包含有关触发器的信息。触发器应该对其执行的插入具有足够的权限。
  • 另外,这看起来有点矫枉过正。为什么数据库用户需要超级用户权限才能对表执行更新?
  • 所有触发器都需要超级用户权限。我不确定这是错误还是功能
  • 这可能因 MySQL 的版本而异。我升级到的版本似乎不需要它。
【解决方案2】:

我从 MySQL 5.0.77 升级到 5.5.15,现在可以正常使用了。

【讨论】:

    【解决方案3】:

    运行这个:

    mysql> flush privileges;
    

    【讨论】:

    • 刷新权限仅在您手动更改 mysql.User 表时才有效。 GRANT 应该会自动完成
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    相关资源
    最近更新 更多