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