mongodb创建管理账户步骤

本文以ubuntu系统配置为例:

1.数据库进入和查看指令

bash 复制代码
mongo      ##进入账户
show dbs   ##查看有哪些数据库
use admin  ##进入管理员数据库admin
show collections  ##查看有哪些数据集合
db.system.users.find()  ##查看当前有哪些管理员账号

2.创建管理员账号

bash 复制代码
db.createUser({user:"guanliyuan",pwd:"password",roles:["root"]})

创建了guanliyuan的账号,密码为password ,可以使用db.system.users.find()再次查看是否已添加成功。

3.关闭免密登录配置

sudo vim /etc/mongod.conf文件,security部分修改如下,并保存退出

bash 复制代码
security:
  authorization: enabled

4.重启mongod服务

bash 复制代码
sudo systemctl restart mongod

5.重新连接mongo数据库

bash 复制代码
mongo ##进入数据库
show dbs ##查看数据库,但因未账号密码登录,故无法显示,会有Unauthorized的错误打印提示
mongo --username guanliyuan --password password --authenticationDatabase admin  ##正确登录到数据库中
show dbs ##用管理员账户登录的可以正常显示数据库信息
相关推荐
悄悄敲敲敲7 小时前
MySQL表的约束
数据库·mysql
鼠爷ねずみ7 小时前
SpringCloud前后端整体开发流程-以及技术总结文章实时更新中
java·数据库·后端·spring·spring cloud
九皇叔叔7 小时前
MySQL 数据库 Read View 详解
数据库·mysql·mvcc·read view
Elastic 中国社区官方博客8 小时前
Elasticsearch:圣诞晚餐 BBQ - 图像识别
大数据·数据库·elasticsearch·搜索引擎·ai·全文检索
cui_win8 小时前
Prometheus实战教程 - Redis 监控
数据库·redis·prometheus
JIngJaneIL9 小时前
基于java + vue个人博客系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
TG:@yunlaoda360 云老大9 小时前
华为云国际站代理商备份策略设置过程中遇到问题如何解决?
服务器·数据库·华为云
SelectDB9 小时前
Doris Catalog 已上线!性能提升 200x,全面优于 JDBC Catalog,跨集群查询迈入高性能分析时代
数据库·数据分析·apache
TAEHENGV9 小时前
进度跟踪模块 Cordova 与 OpenHarmony 混合开发实战
android·javascript·数据库
神秘面具男0310 小时前
MySQL 从基础到实践
数据库·mysql