MySQL 我如何“授予创建用户”作为非 root 用户?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7680973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I "grant create user" as a non-root user?
提问by Gigi
I have a database where I would like users to be able to create new users. That is achievable via GRANT CREATE USER as follows:
我有一个数据库,我希望用户能够在其中创建新用户。这可以通过 GRANT CREATE USER 实现,如下所示:
grant create user on *.* to foo;
This works great and foo can create users. My problem is that the line above works if run as root, but does not work if run as a normal user, even if such user already has the CREATE USER privilege.
这很好用并且 foo 可以创建用户。我的问题是,如果以 root 身份运行,上面的行有效,但如果以普通用户身份运行,则不起作用,即使此类用户已经具有 CREATE USER 权限。
In short, normal users cannot delegate the ability to create users. I have been searching far and wide for any particular privilege you need to be able to do this, and I'm beginning to think it's something that only root can do, although I have found no evidence of this in the MySQL documentation.
总之,普通用户不能委托创建用户的能力。我一直在广泛搜索您需要能够执行此操作的任何特定特权,并且我开始认为这是只有 root 才能执行的操作,尽管我在 MySQL 文档中没有找到这方面的证据。
The question: how can I allow a normal user to let new users create users?
问题:如何让普通用户让新用户创建用户?
采纳答案by Andrej Ludinovskov
Try to run query after grant:
尝试在授权后运行查询:
FLUSH PRIVILEGES;
回答by Gigi
Both answers were useful - I used a combination of both and it seems to have worked.
这两个答案都很有用 - 我使用了两者的组合,它似乎奏效了。
As root (admin is a normal user):
以 root 身份(管理员是普通用户):
mysql> grant create user on *.* to admin with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
As admin (remember, he's a normal user):
作为管理员(请记住,他是普通用户):
mysql> grant create user on *.* to foo with grant option;
Query OK, 0 rows affected (0.00 sec)
Thank you so much.
非常感谢。
回答by Vincy Oommen
-- Create username user
GRANT ALL PRIVILEGES ON `tshirtshop`.*
TO 'username'@'localhost' IDENTIFIED BY 'password'
WITH GRANT OPTION;
回答by duskwuff -inactive-
To be able to GRANT
privileges to other users, a MySQL user must have been created WITH GRANT OPTION
.
为了能够GRANT
授予其他用户的权限,必须已经创建了一个 MySQL 用户WITH GRANT OPTION
。
http://dev.mysql.com/doc/refman/5.1/en/grant.html#grant-other-characteristics
http://dev.mysql.com/doc/refman/5.1/en/grant.html#grant-other-characteristics