MySQL 用户和所有权限

发布于 2024-08-11 02:49:29 字数 472 浏览 7 评论 0原文

好的,我正在尝试将用户添加到 MySQL 数据库。该用户应该能够将其他用户添加到其拥有权限的数据库中。所以我这样做了:

GRANT ALL privileges ON thedbname.* TO 'topuser'@'%' IDENTIFIED BY 'pass';

但是,我这个用户无法添加用户。这是因为我只为单个数据库提供了“全部”吗?当我查看权限时,权限显示为“N”,而如果删除数据库名称,权限将显示为“Y”。

我希望“topuser”能够运行这个:

GRANT SELECT ON thedbname.* TO 'seconduser'@'%' IDENTIFIED BY 'pass';

他们不需要将用户添加到其他数据库,因此我在这里尝试。

这是一个 Web 应用程序,用户提供用户名和密码来访问数据库,这样密码就不会存储在代码中。欢迎其他解决方案!

Ok, I'm trying to add a user to a MySQL database. This user should be able to add other users to the database it has privileges for. So I did this:

GRANT ALL privileges ON thedbname.* TO 'topuser'@'%' IDENTIFIED BY 'pass';

However, I this user cannot add users. Is that because I only gave them 'all' for a single database? The permissions show up as 'N' when I view them whereas if I remove the database name they show as 'Y'.

I want 'topuser' to be able to run this:

GRANT SELECT ON thedbname.* TO 'seconduser'@'%' IDENTIFIED BY 'pass';

They do not need to add users to other databases, hence my attempts here.

This is for a web app where users provide a username and password to access a database so that a password is not stored in the code. Other solutions welcomed though!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

-黛色若梦 2024-08-18 02:49:29

您必须授予“授予其他特权”。 GRANT 手册可在此处获取。

MySQL 仅在 ALL 中包含基本权限,如果你仔细查看文档,它会说全部是:

Grant all privileges at specified access level except GRANT OPTION

所以你应该向你的顶级用户授予“授予选项”:

GRANT GRANT OPTION ON thedbname.* TO 'topuser'@'%' IDENTIFIED BY 'pass';

You have to GRANT the "grant to other privilege". The manual of the GRANT is available here.

MySQL to include only basic privileges in the ALL, if you take a close look at the documentation it says all is :

Grant all privileges at specified access level except GRANT OPTION

so you should grant the "grant option" to your top user :

GRANT GRANT OPTION ON thedbname.* TO 'topuser'@'%' IDENTIFIED BY 'pass';
孤独陪着我 2024-08-18 02:49:29
DELETE FROM mysql.user WHERE user LIKE 'admin';
INSERT INTO mysql.user (host, user, password) VALUES ('localhost', 'admin', 'portal01');
INSERT INTO mysql.user (host, user, password) VALUES ('%', 'admin', 'portal01');
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'portal01' WITH GRANT OPTION;sudo 
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY 'portal01' WITH GRANT OPTION;
FLUSH PRIVILEGES;
SELECT * FROM mysql.user ORDER BY user;
DELETE FROM mysql.user WHERE user LIKE 'admin';
INSERT INTO mysql.user (host, user, password) VALUES ('localhost', 'admin', 'portal01');
INSERT INTO mysql.user (host, user, password) VALUES ('%', 'admin', 'portal01');
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'portal01' WITH GRANT OPTION;sudo 
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY 'portal01' WITH GRANT OPTION;
FLUSH PRIVILEGES;
SELECT * FROM mysql.user ORDER BY user;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文