MongoDB使用者管理筆記

2021-09-24 04:45:27 字數 1946 閱讀 6442

使用者管理:

1 新增唯讀使用者
db.adduser(

"skyman.man","manchungood",true)

2 修改唯讀使用者為普通使用者
db.adduser(

"skyman.man","manchungood",false)

;db.adduser(

"admin","manchungood",false)

;

3 刪除使用者
db.removeuser(

"admin"

);

4 切換資料庫

開啟資料庫,沒有的話立即建乙個

> use admin
5 增加或修改使用者密碼 ,必須在非–auth方式下啟動mongodb,建立使用者,建立完畢,關閉mongodb,以–auth方式啟動mongodb,再以admin使用者登入自己專屬的db
> db.adduser(

'admin','admin'

)

6 檢視使用者列表
> db.system.users.find(

)

7 #使用者認證,要讓登陸的使用者能具有某個db的許可權,必須進入該db,執行auth命令才能生效。
> db.auth(

'admin','pwd'

)

8 刪除使用者對該db的訪問許可權
> db.removeuser(

'mongodb');

#檢視當前db的所有使用者

> show users

9 使用使用者登入mongodb
[root@mongo ~]

# /usr/local/mongodb37018/bin/mongo 127.0.0.1:37017/test -uadmin -padmin

mongodb shell version: 2.0.2

connecting to: 127.0.0.1:37017/test

>

其中test是庫名

10.#檢視所有資料庫

#檢視所有資料庫

> show dbs;

#切換資料庫

> use admin;

#檢視正在使用的資料庫

> db

#檢視當前資料庫裡有多少個collections

show collections

> show dbs

#檢視所有的collection

> show collections

#檢視各collection的狀態

> db.printcollectionstats(

)#檢視主從複製狀態

> db.printreplicationinfo(

)#修復資料庫

> db.repairdatabase(

)#設定記錄profiling,0=off 1=slow 2=all

> db.setprofilinglevel(1)

#檢視profiling

> show profile

#拷貝資料庫

> db.copydatabase(

'mail_addr','mail_addr_tmp'

)#刪除collection

> db.mail_addr.drop(

)#刪除當前的資料庫

> db.dropdatabase(

)primary> use identify;

switched to db identify

#刪除資料庫

primary> db.dropdatabase();

primary>

MongoDB使用者管理

開啟mongodb服務時不新增任何引數時,預設是沒有許可權驗證的,登入的使用者可以對資料庫任意操作而且可以遠端訪問資料庫!在剛安裝完畢的時候mongodb都預設有乙個admin資料庫,此時admin資料庫是空的,沒有記錄許可權相關的資訊!當admin.system.users乙個使用者都沒有時,即使...

Mongodb使用者管理

使用者管理 預設不會驗證使用者名稱密碼。啟動時候新增 auth run with security 1.mongod auth 2.mongo無密碼登入到資料庫中。3.useadmin 切換到admin資料庫 4.db.adduser root 123 新增最高許可權使用者 5.db.auth ro...

MongoDB使用者管理

建立乙個超級使用者 use admin db.createuser 超級使用者的role有兩種,useradmin或者useradminanydatabase 比前一種多加了對所有資料庫的訪問 db是指定資料庫的名字,admin是管理資料庫。用新建立的使用者登入 mongo host u admin...