mongodb 數據庫導出與導入 頂 原

1.導出命令:

切換到項目路徑下bin目錄,執行 ./mongodump -port 28119  -d test -o xxxx (28119爲端口,test爲數據庫名,xxxx爲dump出來的目錄)

示例:./mongodump -port 28119 -d test -o /data/mongoback/

2.導入命令:

切換到項目路徑下bin目錄,執行 ./mongorestore -port 28119 -d test xxxx (28119爲端口,test爲數據庫名,xxxx爲dump出來的目錄)。如需刪除原來的庫再導入加上 –drop 參數。

示例:./mongorestore -port 28119 -d test /data/mongo_recover/mongobackup/test/或

            mongorestore --host=127.0.0.1 --port=28119 -d test  /home/test 

3.客戶端鏈接:

命令:./mongo 127.0.0.1:28119

4.新建用戶:

(1)切換到test 數據庫:use test

(2)新建用戶:db.createUser({user:"test",pwd:"123456",roles:[{role:"readWrite",db:"admin"}]})

(3)查看新建的用戶:show users 或 db.system.users.find()

(4)停止服務器端:db.shutdownServer() 或 kill -9 進程id號

(5)確認mongodb 是否停止: ps aux|grep -i mongo

(6)配置文件 mongodb.conf 文件中添加auth=true (vi mongodb.config),添加認證後所有操作都需要登錄,否則所有的操作都是無效的。

(7)啓動mongodb: ./mongod --config mongodb.conf

(8)密碼登錄:./mongo 127.0.0.1:28119 ----- >use test ----->db.auth("amo","123456")

 

5.刪除用戶:db.system.users.remove({user:"amo"})

 

6.單條數據插入:db.user.insert({"name":"jack","age":20})

 

 

參考鏈接:

http://blog.51cto.com/9040429/1828151

https://www.cnblogs.com/crystaltu/p/6950165.html

https://www.cnblogs.com/pfnie/articles/6759105.html

https://blog.csdn.net/han_cui/article/details/54314728

 

錯誤:mongodb Failed: error connecting to db server: no reachable servers

解決方式:https://blog.csdn.net/wang_zhenwei/article/details/51005935(正確連接服務器端方式:mongorestore --host=127.0.0.1 --port=28119 -d test  /home/test )

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章