首先. 在终端输入 mongo ,并添加超级管理员。
show dbs // 显示所有的数据库 use admin // 切换到admin db.createUser({user:'root',pwd:'root',roles:['userAdminAnyDatabase']}) db.auth('root','root')
1.打开mongoDB数据库,并进入test数据库
(可切换数据库,增加用户)
use test
2.添加一个用户
db.createUser( { user: "xiaogang", pwd: "1438438", roles: ["readWrite"] } )
user文档字段介绍:
user字段,为新用户的名字;
pwd字段,用户的密码;
cusomData字段,为任意内容,例如可以为用户全名介绍;
roles字段,指定用户的角色,可以用一个空数组给新用户设定空角色;
在roles字段,可以指定内置角色和用户定义的角色。
Built-In Roles(内置角色): 1. 数据库用户角色:read、readWrite; 2. 数据库管理角色:dbAdmin、dbOwner、userAdmin; 3. 集群管理角色:clusterAdmin、clusterManager、clusterMonitor、hostManager; 4. 备份恢复角色:backup、restore; 5. 所有数据库角色:readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、dbAdminAnyDatabase 6. 超级用户角色:root 7. 内部角色:__system PS:关于每个角色所拥有的操作权限可以点击上面的内置角色链接查看详情。
spring: data: mongodb: host: 192.1.1.1 port: 49156 username: "xiaogang" password: "1438438" database: test //注意用户名和密码要加上引号
请大家注意数据库的安全性,已经有很多兄弟中招了。幸好这次只是自己的测试库被黑。
All your data is a backed up. You must pay 0.01 BTC to bc1q2hw0np4a5jdwnsygs6839m7z30aku5l6deqtky 48 hours for recover it. After 48 hours expiration we will leaked and exposed all your data. In case of refusal to pay, we will contact the General Data Protection Regulation, GDPR and notify them that you store user data in an open form and is not safe. Under the rules of the law, you face a heavy fine or arrest and your base dump will be dropped from our server! You can buy bitcoin here, does not take much time to buy https://localbitcoins. com with this guide https://localbitcoins.com/guides/how-to-buy-bitcoins After paying write to me in the mail with your DB IP: georgefloyd666@cock.liyourdad4@cock.li