Home > Database > Mysql Tutorial > MongoDB学习笔记三 – 用户授权

MongoDB学习笔记三 – 用户授权

WBOY
Release: 2016-06-07 16:31:16
Original
1280 people have browsed it

#选择admin数据库use admin;#创建一个用户名为root,密码为root的帐户;db.addUser("root", "root"); #执行查看数据表,发现失败,需要登陆。show collections; 所以我们重新登录test数据库 /usr/local/mongodb/bin/mongo -uroot -proot localhost:27017/tes

#选择admin数据库
use admin;
#创建一个用户名为root,密码为root的帐户;
db.addUser("root", "root");
Copy after login
#执行查看数据表,发现失败,需要登陆。
show collections;
Copy after login

所以我们重新登录test数据库

/usr/local/mongodb/bin/mongo -uroot -proot localhost:27017/test
Copy after login

发现还是失败,因为授权的是admin数据库,所以:

/usr/local/mongodb/bin/mongo -uroot -proot localhost:27017/admin
Copy after login

user test
创建一个用户名为test,密码为123的帐户;
show dbs;

因为用户test只是test数据的用户,只有admin数据库的用户才是超级管理员,可以查看任何数据库

启动服务的时候请加上–auth的选项

/usr/local/mongodb/bin/mongod --auth --dbpath=/usr/local/mongodb/data/ --logpath=/usr/local/mongodb/dblogs --fork
Copy after login

MongoDB才会进行认证

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template