当 mongo数据库启动服务时,使用了 认证机制,在使用mongoexport导出集合文件时,需要用户权限认证。

开启数据库认证服务: mongod --auth

导出mongo中集合文件:

mongoexport -d test -c rgc -o /mnt/g/rgc.json -u root -p dfdf --authenticationDatabase=test

参数:

  • -d 需要导出的数据库
  • -c 集合
  • -o 导出文件位置及名称
  • -u 用户名
  • -p 密码
  • --authenticationDatabase 需要导出的数据库

如果没有进行服务开启时数据库认证,则不需要 -u -p  --authenticationDatabase= 这三个参数

如果执行成功显示:

2018-08-16T17:29:06.177+0800 connected to: localhost
2018-08-16T17:29:06.179+0800 exported 2 records

如果显示:

2018-08-16T17:29:02.783+0800    error connecting to db server: server returned error on SASL authentication step: Authentication failed.

则是因为 用户权限不足造成,两种或多种解决方法

  • readWrite权限没有导出数据库的权限,需要给用户添加 dbOwner(在当前DB中执行任意操作)权限,命令如下:

db.createUser({user:'rgc',pwd:'dfdf',roles:[{role:'dbOwner',db:'test'}]})     # 给rgc用户设置密码,并且有  test 数据库的  dbOwner权限  【需要有添加用户的权限,可以先取消服务改为非认证机制】

然后进行如下操作,便可成功

mongoexport -d test -c rgc -o /mnt/g/rgc.json -u rgc -p dfdf --authenticationDatabase=test

  • 使用root权限进行操作

db.createUser({user:'root',pwd:'dfdf',roles:[{role:'root',db:'admin'}]})  #添加root权限 【需要有添加用户的权限】

然后进行如下操作,便可成功

mongoexport -d test -c rgc -o /mnt/g/rgc.json -u root -p dfdf --authenticationDatabase=test

#相关连接:

https://docs.mongodb.com/manual/reference/built-in-roles/#dbAdminAnyDatabase

https://docs.mongodb.com/manual/reference/method/db.createUser/

https://docs.mongodb.com/manual/reference/program/mongoexport/

https://www.cnblogs.com/zxtceq/p/7690977.html

https://blog.csdn.net/u011191463/article/details/68485529

mongoexport 导出需要授权数据库中的集合 报错 Authentication failed.的更多相关文章

  1. 修改数据库中的内容报错:PropertyAccessException:Null value was assinged to a property of primitive type setter of

    错误原因:totalTime的类型为int,数据库中为NULL,int 类型不能赋值为NULL,只能为0,所以报此异常. 解决方案:将totalTime的类型改为Integer,或者初始化为0

  2. jsp中引入jquery报错:Failed to load resource: the server responded with a status of 404 (Not Found)

    问题描述: 今天自己在搭建spring.springMVC.hibernate框架,搭建完成后,在引入jquery时,发现jquery不管用.我的解决顺序是: 1.检查路径,发现路径没错,另外需要注意 ...

  3. 在Ubuntu中启动./jmeter-server报错Server failed to start: java.rmi.RemoteException: Cannot start. ranxf is a loopback address.解决方法

      执行失败错误信息: root@ranxf:/home/ranxf/apache-jmeter-3.1/bin# ./jmeter-server Writing log file to: /home ...

  4. 解决sever 2008中tomcat的报错 init Failed to initialize end point associated with ProtocolHandler ["http-nio-80"]

    错误现象: 01-Aug-2017 14:59:50.140 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing Protoc ...

  5. python2 + selenium + eclipse 中,通过django生产数据库表的时候报错

    python2 + selenium + eclipse 中,通过django生产数据库表的时候报错 解决: 1.查看自己电脑中,“开始-->控制面板-->管理工具-->服务--&g ...

  6. django在model中添加字段报错

    在以下类中添加 description 字段后, class Colors(models.Model): colors = models.CharField(u'颜色', max_length=10) ...

  7. php中各种http报错的状态码分析

    HTTP会经常遇见错误,本文主要和大家分享php中各种http报错的状态码,希望能帮助到大家. HTTP 错误 400 400 请求出错 由于语法格式有误,服务器无法理解此请求.不作修改,客户程序就无 ...

  8. 解决MyEclipse中的js报错的小方法

    今天,下了个模版,但是导进去的时候发现js会报错.看了下其他都没有错误.而有一个js报错误,请原谅我有点红色强迫症,不能留一点红色 . 错误如下:Syntax error on token " ...

  9. 关于Entity Framework中的Attached报错相关解决方案的总结

    关于Entity Framework中的Attached报错的问题,我这里分为以下几种类型,每种类型我都给出相应的解决方案,希望能给大家带来一些的帮助,当然作为读者的您如果觉得有不同的意见或更好的方法 ...

随机推荐

  1. jquery库的cookie用法

    一个完整设置与读取cookie的页面代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...

  2. sql base and plsql and database

    sql base:  http://www.runoob.com/sql/sql-tutorial.html Oracle系统表整理+常用SQL语句收集: https://www.cnblogs.co ...

  3. nginx日志分割

    mark 参考文章: https://blog.csdn.net/molaifeng/article/details/82667158

  4. ionic页面间跳转的动画实现

    1. 在<ion-view>标签中加入: nav-direction="back"或nav-direction="forward" 2.用$stat ...

  5. 基于 debian 操作系统的 docker 镜像,安装 vim

    基于 debian 操作系统的 docker 镜像,安装 vim,步骤: apt-get update apt-get install vim 注意: 直接运行步骤2,可能会报错: Reading p ...

  6. delphi 多线程之 TEvent 和 TLightweightEvent

    unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...

  7. Eclipse从GitHub下载代码

    转载自:http://blog.csdn.net/u014785687/article/details/73473769 打开git视图(window->show view),搜索git,选择G ...

  8. 关于library cache lock和row cache lock产生的常见原因

    这两个等待事件其实很少出现在top5列表中,一般都没什么印象,在此整理记录以便以后查阅. 常见的library cache lock产生的原因在<高级OWI与Oracle性能调查>这本书和 ...

  9. sql调优2

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...

  10. 基于java webRct webSocket 实现点对点视频 (需要源码的请加支付宝好友)

    打开支付宝首页搜“555176706”领红包,即可加好友 <%@ page language="java" pageEncoding="UTF-8"%&g ...