mongodb給資料庫建立使用者密碼

2021-09-02 04:35:24 字數 566 閱讀 8864

1、使用mongod啟動mongodb

2、使用mongo 進入shell

(1)使用某個資料庫

> use test1

switched to db test1

>

(2)給test1資料庫新增使用者名稱

> db.adduser("nancr","123456")

>

(3)驗證使用者是否新增成功。1表示成功,0表示失敗

> db.auth("nancr","123456")

1

3、使用使用者名稱登陸訪問資料庫

(1)使用mongod --auth啟動mongodb

(2)使用使用者名稱訪問test2資料庫,進入shell

mongo test1 -u nancr -p

mongodb shell version: 2.4.10

enter password:

connecting to: test1

>

MongoDB 建立資料庫

mongodb 建立資料庫的語法格式如下 use database name如果資料庫不存在,則建立資料庫,否則切換到指定資料庫。以下例項我們建立了資料庫 runoob use runoob switched to db runoob db runoob 如果你想檢視所有資料庫,可以使用 show ...

MongoDB 建立資料庫

mongodb 建立資料庫的語法格式如下 use database name如果資料庫不存在,則建立資料庫,否則切換到指定資料庫。以下例項我們建立了資料庫 runoob userunoob switched to db runoob dbrunoob 如果你想檢視所有資料庫,可以使用 show db...

MongoDB 建立資料庫

mongodb 建立資料庫的語法格式如下 use database name如果資料庫不存在,則建立資料庫,否則切換到指定資料庫。以下例項我們建立了資料庫 runoob userunoob switched to db runoob dbrunoob 如果你想檢視所有資料庫,可以使用show dbs...