linux mongo 创建用户
程序员文章站
2022-06-06 22:39:12
...
____tz_zs
启动 mongo 的 shell
$ mongo
MongoDB shell version: 3.2.6connecting to: test
切换到 admin 库
> use admin
switched to db admin查看表
> show collections
system.users
system.version
查看所有的用户
> db.system.users.find()
创建管理员账号
> db.createUser(
{user:'user',
pwd:'passwd',
roles:[
{role:'userAdminAnyDatabase', db:'admin'}
]
})
.切换到具体的库
> use tzzs
switched to db tzzs
.
创建这个数据库的用户
> db.createUser(
... { user: "tz",
... pwd: "tz123456",
... roles: [ { role: "readWrite", db: "tzzs" }]
... }
... )
.
出现下面的文字说明创建成功
Successfully added user: {"user" : "tz",
"roles" : [
{
"role" : "readWrite",
"db" : "tzzs"
}
]
}
查看用户
> show users
{
"_id" : "tzzs.tz",
"user" : "tz",
"db" : "tzzs",
"roles" : [
{
"role" : "readWrite",
"db" : "tzzs"
}
]
}
{
"_id" : "tzzs.tz2",
"user" : "tz2",
"db" : "tzzs",
"roles" : [
{
"role" : "readWrite",
"db" : "tzzs"
}
]
}
.
如果有安装可视化软件,我们可以很明显的看到这个过程
①进入 admin 库的过程,就是在查看这个结构的表
.
②创建管理员账号就是创建了以下这条记录
.
③以下是在 tzzs 库下建的两个用户
.
下一篇: mongo连表查询