最新国产好看的视频,伊人天堂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ì),對大家的學(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í)行注冊制,數(shù)據(jù)庫內(nèi)無內(nèi)容時(shí),無法查看到新建的數(shù)據(jù)庫,操作如下:

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

此時(shí)已完成了一庫一賬號的創(chuàng)建。如果創(chuàng)建用戶提示無權(quán)限,請先使用超級管理員登錄之后切換到對應(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è)賬號的數(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 })

刪除所有用戶(必須具備超級管理權(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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

钦州市| 绥阳县| 江源县| 大关县| 闽清县| 汨罗市| 双流县| 黄大仙区| 安多县| 通化市| 象山县| 阿巴嘎旗| 高尔夫| 安康市| 昌宁县| 彰武县| 博客| 都安| 临海市| 宽城| 乌拉特中旗| 边坝县| 焦作市| 平湖市| 八宿县| 拉孜县| 临潭县| 德化县| 湘潭县| 富顺县| 许昌县| 林周县| 依安县| 根河市| 邹城市| 邓州市| 伊川县| 汕尾市| 黑龙江省| 龙川县| 揭东县|