在 MySQL 中使用数据库名称通配符 GRANT?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2668591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GRANT with database name wildcard in MySQL?
提问by JR Lawhorne
I want to create a user 'projectA' that has the same permissions to every database named 'projectA_%'
我想创建一个用户“projectA”,该用户对名为“projectA_%”的每个数据库都具有相同的权限
I know its possible but MySQL doesn't like my syntax:
我知道这是可能的,但 MySQL 不喜欢我的语法:
grant all on 'projectA\_%'.* to 'projectA'@'%';
Reference: http://dev.mysql.com/doc/refman/5.1/en/grant.html
回答by JR Lawhorne
If I use back-tics instead of single quotes in the syntax, it appears to work just fine:
如果我在语法中使用 back-tics 而不是单引号,它似乎工作得很好:
grant all on `projectA\_%`.* to `projectA`@`%`;
回答by johnson
GRANT ALL PRIVILEGES ON `projectA\_%`.* TO 'projectA'@'%' IDENTIFIED BY 'your_passwd';
back-tics are needed for the database name
数据库名称需要 back-tics
Edited:Underscore is now escaped.
编辑:下划线现在已转义。
回答by Travis
As per MySQL's GRANTdocumentation:
根据 MySQL 的GRANT文档:
The “_” and “%” wildcards are permitted 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 ....
在授予全局或数据库级别权限的 GRANT 语句中指定数据库名称时,允许使用“_”和“%”通配符。这意味着,例如,如果要使用“_”字符作为数据库名称的一部分,则应在 GRANT 语句中将其指定为“\_”,以防止用户能够访问匹配的其他数据库通配符模式;例如, GRANT ... ON `foo\_bar`.* TO ....