- 启动mongodb 报错
lin@lin ~ % mongo
MongoDB shell version v4.4.6
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1
- 网上找了文章看了下,发现是服务没有启动,于是执行命令启动服务
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
- 又遇到报错
lin@lin ~ % mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
about to fork child process, waiting until server is ready for connections.
forked process: 17282
ERROR: child process failed, exited with 14
To see additional information in this output, start without the "--fork" option.
- 看mongo.log文件报错日志发现,可能是没有权限
{"t":{"$date":"2021-08-20T15:49:56.021+08:00"},"s":"E", "c":"NETWORK", "id":23024, "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}}
-
于是加上sudo,启动成功
image.png 参考文章
https://www.cnblogs.com/zmm1996/p/13784092.html
https://www.runoob.com/mongodb/mongodb-osx-install.html