views:

20

answers:

1

normally one would say:

GRANT ALL PRIVILEGES ON . TO 'monty'@'%'

Can we use a wildcard where we can target specific databases only like this:

GRANT ALL PRIVILEGES ON SHOP%.* TO 'monty'@'%'

We would like to give insert privileges to a user on databases that start with prefix "SHOP"

+1  A: 

Yes, you can. See the GRANT Syntax. Here's a quote from that page:

The “_” and “%” wildcards are allowed when specifying database names in GRANT statements that grant privileges at the global or database levels. This means, for example, that if you want to use a “_” character as part of a database name, you should specify it as “\_” in the GRANT statement, to prevent the user from being able to access additional databases matching the wildcard pattern; for example, GRANT ... ON `foo\_bar`.* TO

Mike
thanks but I get an error when doing this: grant select, insert, delete, update on "shop%".* to 'someone'@'localhost'; -> You have an error in your SQL syntax
Jorre
You must use back-ticks around the database name: `grant select, insert, delete, update on \`shop%\`.* to 'someone'@'localhost';`
Mike
that works! thanks a lot mate
Jorre