MySQL 中的 GRANT 的表名可以使用通配符吗

发布于 2024-08-05 13:58:56 字数 279 浏览 2 评论 0原文

MySQL 中是否可以对数据库内的一组表进行 GRANT,例如允许创建和删除某些表名,但不允许创建和删除其他表名?

这些似乎都不起作用:

GRANT SELECT ON  `testdb`.`%_testing` TO  'wildcardtest'@'localhost';
GRANT SELECT ON  `testdb`.`testing%` TO  'wildcardtest'@'localhost';

并且 MySQL 手册似乎没有给出任何答案。

Is it possible in MySQL to do a GRANT to a user on a set of tables within a database, e.g. to allow CREATE AND DROP ing of some table names but not others?

Neither of these seem to work:

GRANT SELECT ON  `testdb`.`%_testing` TO  'wildcardtest'@'localhost';
GRANT SELECT ON  `testdb`.`testing%` TO  'wildcardtest'@'localhost';

and the MySQL manual doesn't seem to give an answer either way.

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

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

发布评论

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

评论(3

青衫儰鉨ミ守葔 2024-08-12 13:58:57

GRANT 语句中唯一有效的通配符是 *

GRANT SELECT ON `testdb`.* TO 'user'@'localhost';
GRANT SELECT ON *.* TO 'privilegeduser'@'localhost';

它是全部或一个;没有将表名与授予的权限进行动态匹配的工具。

The only wildcard that works in the GRANT statement is *

GRANT SELECT ON `testdb`.* TO 'user'@'localhost';
GRANT SELECT ON *.* TO 'privilegeduser'@'localhost';

It's all or one; there's no facility for dynamic matching of table names to granted privileges.

吻泪 2024-08-12 13:58:57

没有。您可以使用逗号分隔表名,但不能在 GRANT 中使用通配符。

Nope. You can separate table names with commas but can't use wildcards in a GRANT.

落花随流水 2024-08-12 13:58:57

创建一个新的空数据库。
授予其对原始数据库的访问权限(使用已经有权访问原始数据库的用户)
在这个新数据库中
CREATE VIEW 测试为 SELECT * from originaldatabase.tablename
WHERE 条件...

然后授予测试用户访问 NewDatabase 的权限
GRANT select on NewDatabase.* to 'testuser'@'localhost'

然后只为您希望 testuser 访问的表创建视图。

另请记住,您可以在视图的 WHERE 部分执行 USER():

示例:
创建视图测试为
select * fromoriginal.customer where mysql_user = USER()

在original.customer中,您必须有一列“mysql_user”
并且允许测试用户查看的每一行都必须将 testuser@localhost 作为条目

testuser 将在数据库“test”中将所有创建的视图视为表

Create a new empty database .
Give it access to the original database ( use a user who allready have access to original database )
in this new database
CREATE VIEW test as SELECT * from originaldatabase.tablename
WHERE conditions...

Then give test user access to NewDatabase whith
GRANT select on NewDatabase.* to 'testuser'@'localhost'

Then only create views for the tables you want testuser to access.

Also remember you can do a USER() in the WHERE part of the view:

example:
create view test as
select * from original.customer where mysql_user = USER()

In the original.customer you must then have a column 'mysql_user'
and every row the test user is allowed to see must have testuser@localhost as a entry

The testuser will see all the created views as tables in the database 'test'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文