当前位置: 移动技术网 > IT编程>数据库>Mysql > mongodb数据的导出和导入

mongodb数据的导出和导入

2020年07月14日  | 移动技术网IT编程  | 我要评论

mongodb导出

进入需要导入的mongo容器,

docker exec -it mongo1 bash

创建保存mongodb的备份文件夹

mkdir /test

下载需要导入的数据库

 mongodump -h 192.168.10.200 --port 27017 -d UPA_Logs -o /test/mongodBack -u admin -p devops@123456@

参数说明:

-h:指明数据库宿主机的IP(需要导出数据库的宿主机IP)
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-o:指明到要导出的文件名
-q:指明导出数据的过滤条件

导入到本mongo中

mongorestore -uadmin -padmin -d UPA_Logs --dir /test/upa_log/ --authenticationDatabase admin

参数说明

-h:指明数据库宿主机的IP
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-o:指明到要备份的文件名
-q:指明备份数据的过滤条件

过程曾经报错:

root@0e12b35ad9d3:/test# mongorestore -uadmin -padmin -d UPA_Logs --dir /test/upa_log/ 
2020-07-12T17:18:53.182+0800	Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.

解决办法:
原因是我添加了超级用户必须授权 。添加:--authenticationDatabase admin

其他:

登录超级用户才能查看数据库

use admin
db.auth("admin","admin")

查看数据库

show dbs

查看集合

show tables

查看集合内容:

db.table_header.find().pretty()

查看主次节点:

rs.status()

本文地址:https://blog.csdn.net/qq_39122146/article/details/107302940

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网