Windows下安装配置MongoDB

官网下载: https://www.mongodb.com/download-center

选择Community Server版本,下载zip包即可

  • mongod: 启动MongoDB服务
  • mongo: MongoDB客户端
  • mongoimport: 导出数据库
  • mongoexport: 导入数据库
  • mongodump: 备份数据库
  • mongorestore: 恢复数据库

(1)启动MongoDB服务

mongod --dbpath D:\mongo

(2)连接MongoDB

> mongo
MongoDB shell version v4.0.6
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("c31ac25f-b77b-4248-ab5e-b70fc1b48578") }
MongoDB server version: 4.0.6
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user

> show dbs  //显示所有的数据库
> use admin  //切换到admin
switched to db admin
> db.createUser({user:'root',pwd:'root',roles:['userAdminAnyDatabase']})  //添加管理用户
Successfully added user: { "user" : "root", "roles" : [ "userAdminAnyDatabase" ] }
> db.auth('root','root')  //验证管理用户
1
> use test  //再切换数据库,并添加用户
switched to db test
> db.createUser({user:'test',pwd:'123456',roles:['readWrite']})
Successfully added user: { "user" : "test", "roles" : [ "readWrite" ] }
>

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/02/25/install-and-config-mongodb-under-windows/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Windows下安装配置MongoDB
官网下载: https://www.mongodb.com/download-center 选择Community Server版本,下载zip包即可 mongod: 启动MongoDB服务 mongo: MongoDB客户端 mongoimpor……
<<上一篇
下一篇>>
文章目录
关闭
目 录