Can wildcards be used on tablenames for a GRANT in MySQL

此生再无相见时 提交于 2019-12-04 03:52:52

问题


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.


回答1:


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.




回答2:


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




回答3:


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'



来源:https://stackoverflow.com/questions/1489427/can-wildcards-be-used-on-tablenames-for-a-grant-in-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!