最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MongoDB數(shù)據(jù)庫用戶角色和權(quán)限管理詳解

 更新時(shí)間:2020年11月09日 10:17:37   作者:任我樂  
這篇文章主要給大家介紹了關(guān)于MongoDB數(shù)據(jù)庫用戶角色和權(quán)限管理的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

查看數(shù)據(jù)庫

使用終端命令行輸入 mongo 登陸 mongodb 之后切換到 admin 庫,并認(rèn)證后可查看所有數(shù)據(jù)庫,操作如下所示:

[root@renwole.com ~]# mongo
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("1ea1-4343-9523-167a101973a9") }
MongoDB server version: 4.4.0
> use admin
> db.auth("admin","InaM6Aip#2JBlWwY")
1
> show dbs
admin  0.000GB
config  0.000GB
local  0.000GB

說明:1 表示認(rèn)證成功,0 表示認(rèn)證失敗,認(rèn)證失敗后查看數(shù)據(jù)庫無任何返回。

創(chuàng)建數(shù)據(jù)庫及用戶

創(chuàng)建一個(gè) renwoledb 數(shù)據(jù)庫并授權(quán) renwole 用戶為該庫的 dbOwner 角色。另外、MongoDB數(shù)據(jù)庫實(shí)行注冊(cè)制,數(shù)據(jù)庫內(nèi)無內(nèi)容時(shí),無法查看到新建的數(shù)據(jù)庫,操作如下:

> use renwoledb
> db.createUser(
  {
   user:"renwole",
   pwd:"renwolecom",
   roles:[{role:"dbOwner",db:"renwoledb"}]
  }
)

此時(shí)已完成了一庫一賬號(hào)的創(chuàng)建。如果創(chuàng)建用戶提示無權(quán)限,請(qǐng)先使用超級(jí)管理員登錄之后切換到對(duì)應(yīng)的數(shù)據(jù)庫再創(chuàng)建即可,如下所示:

MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("7be9-4c30-ad2e-2a5b58127ab7") }
MongoDB server version: 4.4.0
> use renwoledb
switched to db renwoledb
> db.createUser(
   {
    user:"renwole",
    pwd:"renwolecom",
    roles:[{role:"dbOwner",db:"renwoledb"}]
   }
 )
uncaught exception: Error: couldn't add user: command createUser requires authentication :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.createUser@src/mongo/shell/db.js:1343:11
@(shell):1:1

> use admin
switched to db admin
> db.auth("root","renwolecompassword")
1
> use renwoledb
switched to db renwoledb
> db.createUser(
   {
    user:"renwole",
    pwd:"renwolecom",
    roles:[{role:"dbOwner",db:"renwoledb"}]
   }
 )
Successfully added user: {
	"user" : "renwole",
	"roles" : [
		{
			"role" : "dbOwner",
			"db" : "renwoledb"
		}
	]
}

添加 root 用戶,擁有整個(gè) MongoDB 最高權(quán)限,建議取消認(rèn)證模式后,先進(jìn)入到 admin 庫,再添加 root 用戶權(quán)限

> use admin
> db.createUser({user: "root",pwd: "renwolecom",roles: [ { role: "root", db: "admin" } ]})

密碼修改

修改某個(gè)賬號(hào)的數(shù)據(jù)庫密碼需要進(jìn)入到該數(shù)據(jù)庫,認(rèn)證后再修改,否則報(bào)錯(cuò),操作如下:

> use renwoledb
> db.changeUserPassword("renwole", "renwolecompwdnew")
> db.auth("renwole","renwolecompwdnew")
1

刪除用戶及數(shù)據(jù)庫

刪除用戶(必須切換到admin使用最高權(quán)限刪除某個(gè)用戶角色)

> db.system.users.remove({user:"renwole"});
WriteResult({ "nRemoved" : 1 })

刪除所有用戶(必須具備超級(jí)管理權(quán)限才能刪除)

> db.system.users.remove({})

刪除數(shù)據(jù)庫(必須切換到指定的數(shù)據(jù)庫,然后再刪除)

> use renwoledb
switched to db renwoledb
> db.dropDatabase()
{ "ok" : 1 }
>

總結(jié)

到此這篇關(guān)于MongoDB數(shù)據(jù)庫用戶角色和權(quán)限管理的文章就介紹到這了,更多相關(guān)MongoDB用戶角色和權(quán)限管理內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

普兰县| 平塘县| 汤原县| 会泽县| 凉山| 武穴市| 东源县| 潢川县| 社会| 万安县| 石城县| 郁南县| 昭通市| 多伦县| 平湖市| 牟定县| 张家川| 托克托县| 安庆市| 宜黄县| 资溪县| 崇明县| 灌南县| 金门县| 田东县| 陵川县| 湖州市| 深泽县| 南昌市| 滦平县| 秦皇岛市| 海丰县| 彭泽县| 昌吉市| 仲巴县| 凭祥市| 交城县| 石泉县| 咸丰县| 滁州市| 邯郸市|