mongo数据迁移

本文详细介绍了如何使用mongodump和mongorestore命令进行MongoDB数据库的备份与恢复。在备份过程中,强调了参数如--host, -u, -p, -d, -o和--authenticationDatabaseadmin的用法,并指出了解决认证失败问题的方法。在恢复操作中,列举了可能出现的错误情况及对应的解决方案,包括缺少认证参数导致的授权失败问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.数据备份(数据库)

使用mongodump进行mongo数据库备份:
命令:mongodump --host localhost -u root -p root -d vlog -o /root/dump --authenticationDatabase admin
参数解释:
–host: 服务器名称或IP:PORT
-u: 用户名
-p: 密码
-d: 数据库dbname
-o:导出文件的存放路径
–authenticationDatabase admin: 添加–authenticationDatabase admin 参数制定认证数据库
解决报错:Failed: can’t create session: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism “SCRAM-SHA-1”: (AuthenticationFailed) Authentication failed.
在这里插入图片描述

2.数据恢复(数据库)

命令:mongorestore -h localhost -u root -p root123 --db admin dump/test_jia/ --authenticationDatabase admin
-h: 服务器名称或IP:PORT
-u: 用户名
-p: 密码
–db: 数据库dbname,需要恢复的数据库名称
dump/test_jia/:恢复文件的存储路径
–authenticationDatabase admin: 添加–authenticationDatabase admin 参数制定认证数据库
报错场景:
1.-u root -p root123 --authenticationDatabase admin三个参数都未设置时报错:
Failed: error getting auth version of server: (Unauthorized) command getParameter requires authentication
2.-u root -p root123或–authenticationDatabase admin未设置时报错:
error connecting to host: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism “SCRAM-SHA-1”: (AuthenticationFailed) Authentication failed.
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值