Can wildcards be used on tablenames for a GRANT in MySQL

后端 未结 3 1007
再見小時候
再見小時候 2021-01-19 18:19

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 o

相关标签:
3条回答
  • 2021-01-19 18:55

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

    0 讨论(0)
  • 2021-01-19 19:01

    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.

    0 讨论(0)
  • 2021-01-19 19:07

    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'

    0 讨论(0)
提交回复
热议问题