MongdoDB的資料匯出 匯入 備份與恢復

2022-08-05 05:30:16 字數 1724 閱讀 4182

目錄找到伺服器的mongodb路徑find / -name mongo

如本次裝在/data路徑下,名字為mongodb,切換到bin目錄下

引數說明:

-d     資料庫名

-c collection名

-o 輸出的檔名

--type 輸出的格式,預設為json

-f 輸出的字段,如果--type為csv,則需要加上 -f "欄位名"

例項1:匯出json格式

./mongoexport -d 庫名 -c 集合名 --port 埠號 -u 使用者名稱 -p 密碼 --authenticationdatabase admin -o 路徑+檔名
./mongoexport -d osgifamilya -c osgidevicestb --port 20036 -u family -p '123' --authenticationdatabase admin -o /data/osgidevicestb-fp.json
例項2:匯出csv格式,不指定欄位會出錯

./mongoexport -u "family" -p "123"  --port 22004  --authenticationdatabase admin -d cmhigateway -c atemp_dial_task_webtestinfo -f 'deviceid' --type csv -o /data/test/deviceid.csv
引數說明:

-d           資料庫名

-c collection名

--type 匯入的格式,預設json

-f 匯入的欄位名

--headerline 如果匯入的格式是csv,則可以使用第一行的標題作為匯入的字段

--file 要匯入的檔案

例項1:

./mongoimport -u 'family' -p '123' -d cmhigateway -c statisticalcoll --type=json --file=./statisticalcoll.json  --port=20036 --authenticationdatabase=admin
引數說明:

-d 資料庫名

-c collection名

-o 備份的檔案路徑

./mongodump -d testdb -c user -o /tmp
引數說明:

-d 資料庫名

-c collection名

./mongorestore -d 庫名 -c 集合名 備份檔案

資料的匯出匯入

異構資料庫之間資料交換,主要使用txt文字檔案 以下記錄乙個工具的使用 sqluldr.zip主要使用oci庫運算元據庫,效能很好。可以很好的匯出txt文字 使用之前需要安裝oracle客戶端,配置好tnsname user username password tnsname 使用者名稱密碼 sql...

匯入匯出資料

從檔案中裝載資料 hive load data local inpath overwrite into table t2 partition province beijing local linux本地的檔案。無local 是hdfs的檔案 注意 從本地檔案系統中將資料匯入到hive表的過程中,其實...

資料匯入匯出

資料匯入匯出是指sql server資料庫系統與外部系統之間進行資料交換的操作。匯入資料是草外部資料來源中查詢或指定資料,並將其插入到sql server的資料表中的過程,也就是說把其他系統的資料引入到sql server的資料庫中 而匯出資料是將sql server資料庫中的資料轉換為使用者指定格...