MySQL 中的 GRANT 的表名可以使用通配符吗
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GRANT 语句中唯一有效的通配符是 *
它是全部或一个;没有将表名与授予的权限进行动态匹配的工具。
The only wildcard that works in the GRANT statement is *
It's all or one; there's no facility for dynamic matching of table names to granted privileges.
没有。您可以使用逗号分隔表名,但不能在 GRANT 中使用通配符。
Nope. You can separate table names with commas but can't use wildcards in a GRANT.
创建一个新的空数据库。
授予其对原始数据库的访问权限(使用已经有权访问原始数据库的用户)
在这个新数据库中
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'