MongoDB的默认用户名和密码是什么? [英] MongoDB what are the default user and password?
问题描述
我在本地和生产环境中使用相同的连接字符串.
当连接字符串为mongodb://localhost/mydb
I am using the same connection string on local and production.
When the connection string is mongodb://localhost/mydb
什么是用户名和密码? 这样保存是否安全?
What is the username and password? Is it secure to keep it this way?
推荐答案
默认情况下,mongodb没有启用访问控制,因此没有默认用户或密码.
By default mongodb has no enabled access control, so there is no default user or password.
要启用访问控制,请使用命令行选项--auth
或security.authorization配置文件设置.
To enable access control, use either the command line option --auth
or security.authorization configuration file setting.
您可以使用以下过程,或在网站上的启用身份验证中. MongoDB文档.
You can use the following procedure or refer to Enabling Auth in the MongoDB docs.
-
在没有访问控制的情况下启动MongoDB.
Start MongoDB without access control.
mongod --port 27017 --dbpath /data/db1
连接到实例.
Connect to the instance.
mongo --port 27017
创建用户管理员.
Create the user administrator.
use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
使用访问控制重新启动MongoDB实例.
Re-start the MongoDB instance with access control.
mongod --auth --port 27017 --dbpath /data/db1
以用户管理员身份进行验证.
Authenticate as the user administrator.
mongo --port 27017 -u "myUserAdmin" -p "abc123" \
--authenticationDatabase "admin"
这篇关于MongoDB的默认用户名和密码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!