zoukankan      html  css  js  c++  java
  • mongodb导出导入数据

    在使用mongodump导出单个表的时候,遇到了一个错误

    # mongodump --host xxx --port 27017 --username 'admin' -p '123456' -d 数据库 -c 表 --out backup.bak
    Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.

    查了很多资料后,发现是少了一个参数 “--authenticationDatabase admin”,加上之后重新试了下就可以了

    # mongodump --host xxx --port 27017 --username 'admin' -p '123456' --authenticationDatabase admin -d 数据库 -c 表 --out backup.bak

    导出整个库

    # mongodump --host xxx --port 27017 --username 'admin' -p '123456' --authenticationDatabase admin -d 数据库 --out /data0/mongo_data/backup.bak/

    导出后的目录是这样的

    /data0/mongo_data/backup.bak/数据库/a.bson
    /data0/mongo_data/backup.bak/数据库/a.metadata.json
    ...
    ...

    导入整个库

    # mongorestore -h xxx --port 27017 -u admin -p '123456' --authenticationDatabase admin -d 数据库 --drop /data0/mongo_data/backup.bak/数据库/

    连接mongo

    # mongo xxx:27017/admin -u admin -p
  • 相关阅读:
    HDU 1505 & POJ 1964 City Game (递推+扫描法)
    web页面内容优化管理与性能技巧
    POJ2406简单KMP
    poj2418map或者字典树
    poj2418map或者字典树
    POJ2296二分2sat
    POJ2296二分2sat
    poj2186强联通(牛仰慕)
    poj2186强联通(牛仰慕)
    poj2175费用流消圈算法
  • 原文地址:https://www.cnblogs.com/lyc94620/p/11825532.html
Copyright © 2011-2022 走看看