当前位置:网站首页>mongodb跨主机数据库拷贝以及常用命令
mongodb跨主机数据库拷贝以及常用命令
2022-06-27 09:42:00 【Hilbob】
一、工具准备
拷贝mongodb里面的数据库需要用到工具mongodump和mongorestore。下载mongodb时是没有下载上述工具的,可以从这里直接下载解压使用: MongoDB Database Tools
二、数据拷贝
转到上述工具解压的路径,使用如下命令进行指定数据库的拷贝:
mongodump -h dbhost -d dbname -o dbdirectory
# 说明
-h:
MongoDB 所在服务器地址,例如:127.0.0.1,当然也可以指定端口号:127.0.0.1:27017
-d:
需要备份的数据库实例,例如:test
-o:
备份的数据存放位置,例如:c:\data\dump,当然该目录需要提前建立,在备份完成后,系统自动在dump目录下建立一个test目录,这个目录里面存放该数据库实例的备份数据。
三、数据转移与恢复
将上述使用mongodump命令生成的文件复制到另外的主机
在另一台主机上执行:
mongorestore -h <hostname><:port> -d dbname <path>
# 说明
--host <:port>, -h <:port>:
MongoDB所在服务器地址,默认为: localhost:27017
--db , -d :
需要恢复的数据库实例的名称。例如:test,当然这个名称也可以和备份时候的不一样,比如test2
--drop:
恢复的时候,先删除当前数据,然后恢复备份的数据。就是说,恢复后,备份后添加修改的数据都会被删除,慎用哦!
<path>:
mongorestore 最后的一个参数,设置备份数据所在位置,即数据复制所在的路径,例如:c:\data\dump\test。
你不能同时指定 <path> 和 --dir 选项,--dir也可以设置备份目录。
--dir:
指定备份的目录
你不能同时指定 <path> 和 --dir 选项。
这样将会在另外的主机的mongodb下恢复拷贝的数据库。
四、mongodb常用命令
激活mongodb环境
> mongod
激活环境后使用mongodb
> mongo
查看当前有哪些数据库
> show dbs
查看当前连接在哪个数据库下面,可以直接输入db
> db
切换到test数据库下面
> use test
想查看当前数据库下有哪些表collection
> show collections
参考
边栏推荐
- [diffusion model]
- On June 23, the video address of station B in the third episode of rust chat room
- 通俗易懂理解朴素贝叶斯分类的拉普拉斯平滑
- 【生动理解】深度学习中常用的各项评价指标含义TP、FP、TN、FN、IoU、Accuracy
- 队列,双向队列,及其运用
- Source insight 工具安装及使用方法
- Preliminary understanding of pytorch
- One week's experience of using Obsidian (configuration, theme and plug-in)
- es 根据索引名称和索引字段更新值
- Quartz(定时器)
猜你喜欢
随机推荐
我大抵是卷上瘾了,横竖睡不着!竟让一个Bug,搞我两次!
多个类的设计
Curiosity mechanism in reinforcement learning
Rockermq message sending and consumption mode
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
QT运行显示 This application failed to start because it could not find or load the Qt platform plugin
Pakistani security forces killed 7 terrorists in anti-terrorism operation
Semi supervised learning—— Π- Introduction to model, temporary assembling and mean teacher
torchvision.models._utils.IntermediateLayerGetter使用教程
基于STM32设计的蓝牙健康管理设备
unity--newtonsoft.json解析
dns备用服务器信息,dns服务器地址(dns首选和备用填多少)
产品力对标海豹/Model 3,长安深蓝SL03预售17.98万起
One week's experience of using Obsidian (configuration, theme and plug-in)
高等数学第七章微分方程
10 常见网站安全攻击手段及防御方法
Take you to play with the camera module
Win10 add right-click menu for any file
[diffusion model]
Location and solution of network connection failure of primary online mobile terminal Report








