mongodb异常,无法连接
发布于 10 年前 作者 qianjiahao 32788 次浏览 最后一次编辑是 8 年前 来自 问答

今天刚刚开机,启动服务后发现数据库无法访问27017端口,于是就尝试 ./mongo 发现抛出异常:

qianjiahaodeMacBook-Pro:bin qianjiahao$ ./mongo MongoDB shell version: 3.0.0 connecting to: test 2015-03-15T10:38:16.504+0800 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused 2015-03-15T10:38:16.505+0800 E QUERY Error: couldn’t connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at connect (src/mongo/shell/mongo.js:179:14) at (connect):1:6 at src/mongo/shell/mongo.js:179 exception: connect failed

于是又尝试 ./mongod 发现提示中有这一句:

2015-03-15T10:49:24.602+0800 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating

我就按网上说的 删除了/data/db/mongod.lock文件,但是发现还是没有效果,输入./mongod依然提示 上面写道的错误。

2015-03-15T10:49:24.602+0800 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating

后来我天真的删除了mongdb的文件和data/db里的文件,在重新下载后,配置了data/db ,结果发现错误依然存在,小弟新人,希望大家帮帮忙,望解决,谢谢

7 回复

试一下

sudo mongod

@leapon

qianjiahaodeMacBook-Pro:~ qianjiahao$ cd mongodb/ qianjiahaodeMacBook-Pro:mongodb qianjiahao$ ls GNU-AGPL-3.0 THIRD-PARTY-NOTICES README bin qianjiahaodeMacBook-Pro:mongodb qianjiahao$ cd bin qianjiahaodeMacBook-Pro:bin qianjiahao$ ls bsondump mongodump mongoimport mongorestore mongostat mongo mongoexport mongooplog mongos mongotop mongod mongofiles mongoperf mongosniff qianjiahaodeMacBook-Pro:bin qianjiahao$ sudo mongod Password: sudo: mongod: command not found qianjiahaodeMacBook-Pro:bin qianjiahao$

在进入bin后 提示命令无法找到

sudo ./mongod

@leapon 恩 问题解决了,谢谢啦

楼主如何解决的,为什么我一直是连接不上。 屏幕快照 2016-01-18 下午9.57.54.png

如果你是用的mac 就这样

cd 到命令目录下
sudo ./mongod   启动

如果还是连不上 先kill掉进程 再试

回到顶部