1、下载mongodb
https://www.mongodb.com/try/download/community
2、解压

3、重命名

4、创建mongodb的data、logs目录

5、启动mongodb,
bin/mongod --port=27017 --dbpath=/data/program/mongodb/data --logpath=/data/program/mongodb/logs/mongodb.log --bind_ip=0.0.0.0 --fork
如果出现 Illegal instruction (core dumped),应该就是版本问题,降低mongodb.conf
我这里重新下载mongodb,版本是4.4.25
按照上面的步骤,重新来一遍。

7、使用mongo命令进入

8、关闭mongodb
关闭方式1
bin/mongod --port=27017 --dbpath=/data/program/mongodb/data --shutdown

关闭方式2
use admin --进入admin库
db.shutdownServer() --关闭服务
exit --退出shell即可

9、设置用户名、密码
use admin
db.createUser({user: "cht", pwd: "Aa123456",roles:[{role:"root",db:"admin"}]})

10、下载mongodb连接工具。
MongoDB Compass Download (GUI) | MongoDB
window安装后,使用用户名和密码连接就可以。