Providing MySQL for more than one database
No, you cannot, as you can see in the GRANT syntax diagram . While apparently you can use a wildcard *.*
to apply the grant to all databases, but I wouldn't do that.
source to share
From the GRANT documentation ( https://dev.mysql.com/doc/refman/5.7/en/grant.html ):
Wildcards
_
and are%
allowed when specifying database names in statementsGRANT
that grant database-level privileges. This means, for example, that if you want to use a character_
as part of a database name, you must specify it as\_
in the statementGRANT
so that the user cannot access additional databases matching the template pattern; e.g. GRANT ... ON`foo\_bar\`.* TO ....
So, to do the above (mydb1 and mydb2), just do
GRANT ALL PRIVILEGES ON `mydb%`.* TO 'reader'@'localhost';
Etc. (Assuming you don't have mydb3 or mydb_funkytown, etc., that you don't want to grant privileges either.)
See also:
source to share