How to grant on multiple databases? MySQL.
Something like
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE
ON 'databasesprefix%'.*
TO testuser@localhost IDENTIFIED BY 'testpasswd';
MySQL Grant is used to grant privileges to the user account. At first, when we create a new user, he doesn’t have any privilege such as selecting a database and querying data from the table. Such privileges of selecting, inserting, updating, and so on will be given to the user by the superuser.
How to grant on multiple databases? MySQL. GRANT SELECT,INSERT,UPDATE,DELETE,CREATE ON 'databasesprefix%'.* TO testuser@localhost IDENTIFIED BY 'testpasswd'; Show activity on this post. You just need to use backticks instead of quotes around the db_name prefix. GRANT SELECT,INSERT,UPDATE,DELETE,CREATE ON `databasesprefix%`.*
mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost'; GRANT the PRIVILEGES of type ALL (thus everything of course). Note: Most modern MySQL installations do not require the optional PRIVILEGES keyword. These privileges are for database_name and it applies to all tables of that database, which is indicated by the .* that follows.
Now that you are at the mysqlcli prompt, you need only issue the GRANT command with the necessary options to apply the appropriate permissions. The GRANT command is capable of applying a wide variety of privileges, everything from the ability to CREATE tables and databases, read or write FILES, and even SHUTDOWN the server.
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';
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With