#新安装mongo后,第二次连接出现下面错误 root@jeff:/opt/program/python# mongo MongoDB shell version: 2.0.6 connecting to: test Thu Apr 11 10:04:39 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84 exception: connect failed
原因:
创建数据库时,是自己指定的数据库,
当第二次连接时,如果使用的是自动加载服务,就会出现不能连接的错误,如上面情况所述。
解决方法:
1、可以使用mongod --dbpath /path/to/your/dbdata
2、如果相隔时间较长,忘记了上次指定的数据库path(这种情况很容易发生),那么采用下面的方法:
删除 /var/lib/mongodb/mongod.lock 文件
重启 sudo /etc/init.d/mongodb restart
即可:
#删除 root@jeff:/opt# rm /var/lib/mongodb/mongod.lock #重启: root@jeff:/opt# /etc/init.d/mongodb restart Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service mongodb restart Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the stop(8) and then start(8) utilities, e.g. stop mongodb ; start mongodb. The restart(8) utility is also available. mongodb start/running, process 12569 #连接: root@jeff:/opt# mongo MongoDB shell version: 2.0.6 connecting to: test >