我可以授予对前缀为通配符的数据库的访问权限吗? [英] Can I grant access to databases with prefix then wild card?
问题描述
我可以GRANT ALL PRIVILEGES ON a*.* TO 'my_user'@'%' WITH GRANT OPTION;
吗?
我只希望用户只能访问以"my_prefix_"开头的所有数据库,而不能访问"mysql".
I just want the user to only have access to all databases beginning with "my_prefix_" but not, for instance, to "mysql".
推荐答案
是的,可以.
这是当我让用户jaap
并使用选项Grant all privileges on wildcard name (username\_%)
时phpMyAdmin所做的事情:
This is what phpMyAdmin does when I make a user jaap
and use the option Grant all privileges on wildcard name (username\_%)
:
GRANT ALL PRIVILEGES ON `jaap\_%` . * TO 'jaap'@'localhost';
那是你的意思,对吧?
PS
如您所见,_
被转义了,因为在(My)SQL中未转义的_
表示一个字符". (类似于regex中的.
.)在这种情况下,您希望_
为文字,因此数据库必须以jaap_
PS
As you can see, the _
is escaped, because in (My)SQL an unescaped _
means 'one character'. (Like .
in regex.) In this case, you want the _
to be literal, so databases must start with jaap_
这篇关于我可以授予对前缀为通配符的数据库的访问权限吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!