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 ##用管理员账户登录的可以正常显示数据库信息
相关推荐
m0_734949791 小时前
MySQL如何配置定时清理过期备份文件_find命令与保留周期策略
jvm·数据库·python
m0_514520572 小时前
MySQL索引优化后性能没提升_通过EXPLAIN查看索引命中率
jvm·数据库·python
NaMM CHIN2 小时前
sql实战解析-sum()over(partition by xx order by xx)
数据库·sql
不瘦80斤不改名2 小时前
深入浅出 MySQL(一):一文理清 SQL 核心规范与五大分类
数据库·sql·mysql
woniu_buhui_fei2 小时前
MySQL知识整理二
数据库·mysql
Polar__Star3 小时前
如何在 AWS Lambda 中正确使用临时凭证生成 S3 预签名 URL
jvm·数据库·python
Lucifer三思而后行3 小时前
zCloud 中 Oracle 实例状态未知问题记录
数据库·oracle
island13143 小时前
最详细VMware Workstation 17 上安装 Ubuntu 系统
linux·数据库·ubuntu
卢傢蕊3 小时前
MongoDB
数据库·mongodb
m0_743623923 小时前
React 自定义 Hook 的命名规范与调用规则详解
jvm·数据库·python