当前位置:网站首页>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
参考
边栏推荐
- Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
- Use aspese Cells convert Excel to PDF
- [STM32] Hal library stm32cubemx tutorial 12 - IIC (read AT24C02)
- Source insight 工具安装及使用方法
- 【报名】基础架构设计:从架构热点问题到行业变迁 | TF63
- 小哥凭“量子速读”绝技吸粉59万:看街景图0.1秒,“啪的一下”在世界地图精准找到!...
- 新旧两个界面对比
- Apache POI的读写
- [diffusion model]
- E+h secondary meter repair pH transmitter secondary display repair cpm253-mr0005
猜你喜欢

初步认识pytorch

Tdengine invitation: be a superhero who uses technology to change the world and become TD hero

TDengine 邀请函:做用技术改变世界的超级英雄,成为 TD Hero

Video file too large? Use ffmpeg to compress it losslessly
![[200 opencv routines] 211 Draw vertical rectangle](/img/57/5ff4ccb6f003e1ec6c49de8c8fde16.png)
[200 opencv routines] 211 Draw vertical rectangle

Markem imaje马肯依玛士喷码机维修9450E打码机维修

Principle and application of the most complete H-bridge motor drive module L298N

详细记录YOLACT实例分割ncnn实现
![[200 opencv routines] 212 Draw a slanted rectangle](/img/cf/da8fff386d011c939946326c55671f.png)
[200 opencv routines] 212 Draw a slanted rectangle

Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
随机推荐
unity--newtonsoft.json解析
HiTek电源维修X光机高压发生器维修XR150-603-02
反编译jar包,修改后重新编译为jar包
DNS standby server information, DNS server address (how many DNS preferred and standby are filled in)
Win10 add right-click menu for any file
Brief introduction to SSL encryption process
Installation and use of SVN version controller
提高效率 Or 增加成本,开发人员应如何理解结对编程?
TDengine 邀请函:做用技术改变世界的超级英雄,成为 TD Hero
This application failed to start because it could not find or load the QT platform plugin
12个网络工程师必备工具
Unity - - newtonsoft. Analyse json
队列,双向队列,及其运用
如何获取GC(垃圾回收器)的STW(暂停)时间?
main()的参数argc与argv
Digital ic-1.9 understands the coding routine of state machine in communication protocol
R language uses econcharts package to create microeconomic or macro-economic charts, demand function to visualize demand curve, and customize the parameters of demand function to enrich the visualizat
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
C# Any()和AII()方法
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!