Grant on multiple databases. MySQL

23,286

Solution 1

your example should work. from the (5.5) manual:

The “_” and “%” wildcards are allowed when specifying database names in GRANT statements that grant privileges at the global or database levels.

with % matching any number (even zero) of characters, and _ matching exactly one character. if you want a _ in your database name, you have to escape it as \_. also watch the other caveats from the manual.

<UPDATE>as the other answer points out: if the database name contains wildcards, it has to be quoted with the identifier quote character, the backtick (“`”)</UPDATE>

Solution 2

You just need to use backticks instead of quotes around the db_name prefix.

I think this will work:

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE
ON `databasesprefix%`.*
TO testuser@localhost IDENTIFIED BY 'testpasswd';
Share:
23,286
shurik2533
Author by

shurik2533

Everything should be made as simple as possible, but no simpler. Albert Einstein

Updated on July 29, 2022

Comments

  • shurik2533
    shurik2533 almost 2 years

    How to grant on multiple databases? MySQL.

    Something like

    GRANT SELECT,INSERT,UPDATE,DELETE,CREATE
    ON 'databasesprefix%'.*
    TO testuser@localhost IDENTIFIED BY 'testpasswd';
    
  • quantumSoup
    quantumSoup almost 14 years
    "You can't use wildcards in the db_name of a grant statement." Yes you can.