mongodb mongo 的命令行身份验证失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15272521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
command line authentication of mongo fails
提问by RickyA
I am running mongo 2.2.2 on osx.
我在 osx 上运行 mongo 2.2.2。
When I do the following authentication is going fine:
当我执行以下身份验证时,一切正常:
$ mongo
>> use admin
>> db.auth("uname", "password")
log:
日志:
Thu Mar 7 13:51:08 [initandlisten] connection accepted from 127.0.0.1:63474 #10 (4 connections now open)
Thu Mar 7 13:51:08 [conn10] authenticate db: admin { authenticate: 1, nonce: "123", user: "uname", key: "456" }
However when I try to authenticate directly from the commandline:
但是,当我尝试直接从命令行进行身份验证时:
$ mongo admin -u uname -p password
I get the following error:
我收到以下错误:
Thu Mar 7 14:25:52 [initandlisten] connection accepted from 127.0.0.1:63939 #12 (5 connections now open)
Thu Mar 7 14:25:52 [conn12] authenticate db: admin { authenticate: 1, nonce: "789", user: "uname", key: "147" }
Thu Mar 7 14:25:52 [conn12] auth: key mismatch uname, ns:admin
Thu Mar 7 14:25:52 [conn12] end connection 127.0.0.1:63939 (4 connections now open)
Does anyone know what causes this?
有谁知道是什么原因造成的?
回答by ronasta
A password containing special characters, especially the dollar sign, has to be put in single quotes to protect them from the command shell:
包含特殊字符(尤其是美元符号)的密码必须放在单引号中以保护它们免受命令 shell 的影响:
$ mongo admin -u uname -p 'password'
回答by user6155548
You have to user the --authenticationDatabase
to indicate mongodb where to find the user you have created. For example:
您必须使用--authenticationDatabase
来指示 mongodb 在哪里可以找到您创建的用户。例如:
mongo admin -u uname -p 'password' --authenticationDatabase admin
回答by Hasib Kamal
This is the way to access an authenticate MongoDB database from terminal
这是从终端访问经过身份验证的 MongoDB 数据库的方法
mongo -u user_name -p "your_password" host_name/database_name
Ex:
前任:
mongo -u hasib -p "123456" localhost/my_db
回答by Prashanth Muthurajaiah
To Login to MongoDB Via Command Line do the following
要通过命令行登录到 MongoDB,请执行以下操作
$ mongo admin -u 'username' -p 'Password'