stivlo
stivlo

Reputation: 85486

MySQL grant syntax and wildcards

To allow someuser to do SELECTs on mydb, I can execute the following statement:

GRANT SELECT ON mydb.* TO 'someuser'@'somehost';

Suppose that I want allow SELECTs on only two tables: event and event_detail.

I guess I can do the following:

GRANT SELECT ON mydb.event TO 'someuser'@'somehost';
GRANT SELECT ON mydb.event_detail TO 'someuser'@'somehost';

Would the following also work? (Supposing no other tables are matched)

GRANT SELECT ON mydb.event* TO 'someuser'@'somehost';

Upvotes: 0

Views: 344

Answers (2)

Cynical
Cynical

Reputation: 9568

Based on the GRANT syntax:

GRANT
... priv_level ...

priv_level:
    *
  | *.*
  | db_name.*
  | db_name.tbl_name
  | tbl_name
  | db_name.routine_name

So I guess you can't. You can, anyway, use the INFORMATION_SCHEMA to find those tables with the name prefix you desire, and then iterate through them.

Upvotes: 1

D Mac
D Mac

Reputation: 3809

No - wildcards can only be used for entire table or database names.

You'll have to either type the grant statement for every table explicitly, or write a script or program to do it for you.

Upvotes: 1

Related Questions