我可以授予对前缀为通配符的数据库的访问权限吗? [英] Can I grant access to databases with prefix then wild card?

查看:59
本文介绍了我可以授予对前缀为通配符的数据库的访问权限吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆