立即注册 登录
About云-梭伦科技 返回首页

langke93的个人空间 https://www.aboutyun.com/?1415 [收藏] [复制] [分享] [RSS]

日志

MongoDB登陆

热度 1已有 1901 次阅读2017-2-22 17:53

1.mongo 远程连接

配置mongodb.conf,注释掉bind_ip

 #bind_ip = 127.0.0.1   //注释此行

 

启用认证登陆

auth = true       //将此行前的注释去掉

 

登陆(authenticationDatabase 验证数据库)

mongo host:port/dbname -u user-p password --authenticationDatabase dbname 

mongo 127.0.0.1:27017/admin -u root -p 123456 --authenticationDatabase admin

 

正确关闭mongod 的方法

use admin

db.shutdownServer()

 

 

用户操作认证 

db.auth("user","password")

全部用户 

show users // db.system.users.find()  

// 新建用户

// 超级用户 root

db.createUser({user: "root",pwd: "123456",roles: [ "root" ]})

// 用户管理权限 userAdminAnyDatabase

db.createUser({user:"userAdmin",pwd:"123456",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})

// 数据库管理权限 dbAdminAnyDatabase

db.createUser({user:"dbAdmin",pwd:"123456",roles:[{role:"dbAdminAnyDatabase",db:"admin"}]})

// 数据读写用户 readWriteAnyDatabase

use test

db.createUser({user:"sa",pwd:"sa",roles:[{role:"readWrite",db:"test"}]})

// 已废弃的方法 相当于新建 { "user" : "root", "roles" : [ "dbOwner" ] }

 

// db.addUser("root","123456") 

// 修改密码 db.changeUserPassword("root", "root")

// 删除原用户 db.dropUser("test") // db.system.users.remove({user:"test"});

 

角色权限

展示角色 show roles;

// 查看当前用户的权限 db.runCommand({usersInfo:"root",showPrivileges:true})

// 查看角色权限 db.getRole( "dbAdminAnyDatabase", { showPrivileges: true } )


路过

雷人

握手

鲜花

鸡蛋

发表评论 评论 (1 个评论)

回复 ljlinux2012 2017-3-1 17:13
顶顶顶顶顶顶

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

关闭

推荐上一条 /2 下一条