Failed: error connecting to db server: server returned error on SASL authentication step: Authentica

男娘i 2021-11-09 21:04 1409阅读 0赞

mongo备份失败

mongodump -h 127.0.0.1:27017 -d stu -u python -p python -o /opt

报错:

2019-08-01T03:05:21.655-0700 Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
更改如下:

mongodump -h 127.0.0.1:27017 -d stu -u python -p python --authenticationDatabase admin -o /opt

成功

备份恢复

mongorestore -h 127.0.0.1:27017 -u python -p python -d haha —dir /opt/stu
报错:

Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
然后执行如下:

mongorestore -h 127.0.0.1:27017 -u python -p python --authenticationDatabase admin -d haha —dir /opt/stu
成功

二:数据的导入与导出

导出

模板:

mongoexport -h dbhost -d dbname -c colname -o filename —type json/csv -f field

  1. -h: 服务器地址
  2. -d: 数据库名
  3. -c: 集合名
  4. -o: 导出文件名
  5. --type: 文件类型,默认json格式,可选数据类型jsoncsv
  6. -f: 需要导出的字段,导出为json格式的数据时可以不指定导出哪些字段,默认全部,导出成csv文件是必须指定

mongoexport -h 127.0.0.1:27017 -u python -p python -d haha --authenticationDatabase admin -c stu -o /opt/haha.json —type json

导入

模板:

mongoimport -d dbname -c collectionname —file filename —headerline —type json/csv -f field

  1. -d :数据库名
  2. -c collection
  3. --type :导入的格式默认json
  4. -f :导入的字段名
  5. --headerline :如果导入的格式是csv,则可以使用第一行的标题作为导入的字段
  6. --file :要导入的文件

eg:mongoimport -d two -c newstu —file ./test.json —type json
eg:mongoimport -d two -c newstu —file ./test.csv —type csv —headerline

mongoimport -d haha -u python -p python --authenticationDatabase admin -c jjj —file ./haha.json —type json

发表评论

表情:
评论列表 (有 0 条评论,1409人围观)

还没有评论,来说两句吧...

相关阅读