当前位置:网站首页>Mongodb cross host database copy and common commands
Mongodb cross host database copy and common commands
2022-06-27 09:59:00 【Hilbob】
One 、 Tool preparation
Copy mongodb The database inside needs tools mongodump and mongorestore. download mongodb You did not download the above tools , You can download and decompress it directly from here : MongoDB Database Tools
Two 、 Data copy
Go to the path extracted by the above tool , Use the following command to copy the specified database :
mongodump -h dbhost -d dbname -o dbdirectory
# explain
-h:
MongoDB Address of the server , for example :127.0.0.1, Of course, you can also specify the port number :127.0.0.1:27017
-d:
Database instances that need to be backed up , for example :test
-o:
Backup data storage location , for example :c:\data\dump, Of course, the directory needs to be established in advance , After the backup is complete , The system is automatically in dump Create one in the directory test Catalog , This directory contains the backup data of the database instance .
3、 ... and 、 Data transfer and recovery
Use the above mongodump The file generated by the command is copied to another host
Execute on another host :
mongorestore -h <hostname><:port> -d dbname <path>
# explain
--host <:port>, -h <:port>:
MongoDB Address of the server , The default is : localhost:27017
--db , -d :
The name of the database instance to be recovered . for example :test, Of course, this name can also be different from the backup time , such as test2
--drop:
When you recover , Delete the current data first , Then restore the backup data . That is to say , After recovery , The data added and modified after backup will be deleted , Use with caution !
<path>:
mongorestore The last parameter , Set the location of backup data , That is, the path where the data replication is located , for example :c:\data\dump\test.
You can't specify at the same time <path> and --dir Options ,--dir You can also set the backup directory .
--dir:
Specify the directory to back up
You can't specify at the same time <path> and --dir Options .
This will be done on another host mongodb Restore the copied database .
Four 、mongodb Common commands
Activate mongodb Environmental Science
> mongod
Use after activating the environment mongodb
> mongo
See which databases are currently available
> show dbs
Check which database is currently connected to , You can input db
> db
Switch to test Under database
> use test
You want to view the tables under the current database collection
> show collections
Reference resources
边栏推荐
猜你喜欢

三层架构中,数据库的设计在哪一层实现,不是在数据存储层吗?

谷歌浏览器 chropath插件

通俗易懂理解樸素貝葉斯分類的拉普拉斯平滑

Your brain is learning automatically when you sleep! Here comes the first human experimental evidence: accelerate playback 1-4 times, and the effect of deep sleep stage is the best
Scientists develop two new methods to provide stronger security protection for intelligent devices

SVN版本控制器的安装及使用方法

prometheus告警流程及相关时间参数说明

基于STM32设计的蓝牙健康管理设备

QT运行显示 This application failed to start because it could not find or load the Qt platform plugin

There is no doubt that this is an absolutely elaborate project
随机推荐
unity--newtonsoft.json解析
Scientists develop two new methods to provide stronger security protection for intelligent devices
视频文件太大?使用FFmpeg来无损压缩它
LVI Sam summary
6月23日《Rust唠嗑室》第三期B站视频地址
R语言使用caret包的preProcess函数进行数据预处理:对所有的数据列进行center中心化(每个数据列减去平均值)、设置method参数为center
【SO官方采访】为何使用Rust的开发者如此深爱它
使用Aspose.cells将Excel转成PDF
mongodb跨主机数据库拷贝以及常用命令
上周热点回顾(6.20-6.26)
dns备用服务器信息,dns服务器地址(dns首选和备用填多少)
There is no doubt that this is an absolutely elaborate project
Use CAS to complete concurrent operations with atomic variables
手把手带你玩摄像头模组
感应电机直接转矩控制系统的设计与仿真(运动控制matlab/simulink)
leetcode:522. 最长特殊序列 II【贪心 + 子序列判断】
Unity - - newtonsoft. Analyse json
js的数组拼接「建议收藏」
Installation and usage of source insight tool
C language learning day_ 04