天天看點

mongodb導出導入資料庫

1、mongodump備份資料庫(導出資料庫)

mongodump -h IP --port 端口 -u 使用者名 -p 密碼 -d 資料庫 -o 檔案存在路徑

如:mongodump -h 127.0.0.1 -o /root

(1、如果沒有使用者誰,可以去掉-u和-p)

(2、如果導出本機的資料庫,可以去掉-h)

(3、如果是預設端口,可以去掉–port)

(4、如果想導出所有資料庫,可以去掉-d)

mongodb導出導入資料庫

2、mongorestore還原資料庫

mongorestore -h IP --port 端口 -u 使用者名 -p 密碼 -d 資料庫 --drop 檔案存在路徑

(–drop的意思是,先删除所有的記錄,然後恢複。)

(1)恢複所有資料庫到mongodb中

mongorestore /home/deng/mongodb/

mongorestore -h 127.0.0.1 -d test --dir /root/test

如:

mongorestore -h dbhost -d dbname --dir dbdirectory

(2)還原指定的資料庫

mongorestore -d tank /home/zhangy/mongodb/tank/

參考

https://www.jb51.net/article/52498.htm

https://www.cnblogs.com/whybxy/p/8607795.html