当前位置:首页 > IT技术 > 数据库 > 正文

MySQL、MongoDB权限细化记录
2022-02-14 10:39:17

MySQL、MongoDB权限细化记录



背景

经常需要给第三方开放数据库权限,由于是第三方,所以对于开放的权限需要细化到某个库的某个表,某个库的某个集合,以下记录一下。

MySQL

创建一个 xxxx 用户,对 xx 库的 yy 表有只读权限,语句如下:

grant select  on xx.yy to xxxx@'%' identified by 'xxxxxxxxxxxxxxx';

当需要回收该权限时,语句如下

revoke SELECT ON xx.yy from 'xxxx'@'%'

Mongodb

创建一个 xxxx 用户,对 xx 库的 yy、zz 集合有只读权限,语句如下:

use xx
db.createUser(
{
user: "xxxx",
pwd: "xxxxxxxxxxxxxx", // or cleartext password
roles: [
{ role: "read", db: "xx", collection: "yy" },
{ role: "read", db: "xx", collection: "zz" },
]
}
)



本文摘自 :https://blog.51cto.com/u