gpt4 book ai didi

mysql - 允许具有有限数据库访问权限的 MySQL 用户创建更多具有类似访问权限的用户

转载 作者:行者123 更新时间:2023-11-29 02:50:48 24 4
gpt4 key购买 nike

我知道我可以创建一个具有 create user 权限的用户,如下所示:

create user primary_user identified by 'pass';
grant all on *.* to primary_user with grant option;

这将允许我在使用 primary_user 登录时创建用户。

现在假设我有一个数据库子集,所有数据库都带有前缀 abc_,并且我希望我的 primary_user 只能访问这些数据库。

然后上面的grant查询看起来像这样:

grant all on `abc_%`.* to `primary_user` with grant option;

但是,现在的问题是,当我使用 primary_user 登录并尝试创建 secondary_user 时,出现以下错误:

ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation

长话短说

基本上我想要的是 primary_user 只能访问带有 abc_ 前缀的数据库,并且还能够创建次级用户,而这些次级用户反过来也只有使用 abc_ 前缀访问数据库。

这可能吗?还是我使用在 *.* 上具有 create user 权限的用户帐户创建二级用户的唯一选择?

最佳答案

MySQL Documentation 中所述:

To use CREATE USER, you must have the global CREATE USER privilege or the INSERT privilege for the mysql database.

因此,在特定数据库中具有权限的用户不能创建用户。当然,由于您有 with grant option,您的 primary_user 可以将所有数据库级别的权限授予其他已创建的用户(对于 abc_ 数据库)。

注释 #1:Here您会发现一个有趣的表,其中包含各种权限以及可以授予它们的不同级别。

注意 #2:在向非管理员用户授予 G​​RANT OPTIONS 时要格外小心,因为他们可以修改其他用户的权限,这可能会导致困惑Open Web Application Security Project状态:

[Grant privilege]... should be appropriately restricted to the DBA and Data (Table) owners. Give specific permissions on an as needed basis and use different logins for different purposes.

关于mysql - 允许具有有限数据库访问权限的 MySQL 用户创建更多具有类似访问权限的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36159318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com