如何在 mac OS X 上启动 mongodb 服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31564526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to start a mongodb service on mac OS X?
提问by nshetty
I have already installed Mongodb on my mac but the process is currently not running. How do I start the Mongodb service so that I can start using the commands?
我已经在我的 Mac 上安装了 Mongodb,但该进程目前没有运行。如何启动 Mongodb 服务以便我可以开始使用命令?
采纳答案by bagrat
Try the following steps in Terminal:
在终端中尝试以下步骤:
which mongod
This will output the path to your mongod
, but if it is not in your $PATH
the command output will be empty. So you need to find your executable:
这将输出您的 路径mongod
,但如果它不在您$PATH
的命令中,则命令输出将为空。所以你需要找到你的可执行文件:
find / -name 'mongod'
In the output of this command, you will see many lines, one of which will be like bin/mongod
, e.g. /usr/local/mongodb/bin/mongod
. In that case take the whole absolute path and do the following:
在此命令的输出中,您将看到许多行,其中之一类似于bin/mongod
,例如/usr/local/mongodb/bin/mongod
。在这种情况下,采用整个绝对路径并执行以下操作:
echo "PATH=/usr/local/mongodb/bin/:$PATH" >> ~/.bash_profile
. ~/.bash_profile
Then try again:
然后再试一次:
mongod --dbpath /your/path
回答by kinxiel
If you used homebrew to install MongoDB on macOS you type the following in terminal. Should do the trick in most cases.
如果您使用自制软件在 macOS 上安装 MongoDB,请在终端中键入以下内容。在大多数情况下应该可以解决问题。
$ brew services start mongodb
回答by Brian Kurz
To start the mongodb, you should only have to run the "mongod" command on the terminal.
要启动 mongodb,您只需在终端上运行“mongod”命令。
回答by Sundar
Just go into a folder where you want mongodb to store all the database files and run the command
只需进入您希望 mongodb 存储所有数据库文件的文件夹并运行命令
mongod --dbpath=.
mongod --dbpath=.
回答by Emir Mamashov
Install and Run MongoDB with Homebrew
使用 Homebrew 安装和运行 MongoDB
Open the Terminal app and type
打开终端应用程序并输入
brew update
酿造更新
After updating Homebrew
更新 Homebrew 后
brew install [email protected]
酿造安装 [email protected]
After downloading Mongo, create the “db” directory. This is where the Mongo data files will live. You can create the directory in the default location by running
下载 Mongo 后,创建“db”目录。这是 Mongo 数据文件所在的位置。您可以通过运行在默认位置创建目录
sudo mkdir -p /data/db
须藤 mkdir -p /数据/数据库
Make sure that the /data/db directory has the right permissions by running
通过运行确保 /data/db 目录具有正确的权限
sudo chown -R
id -un
/data/db
须藤 chown -R
id -un
/data/db
Run the Mongo daemon, in one of your terminal windows run
运行 Mongo 守护进程,在您的终端窗口之一中运行
brew services start mongodb-community
brew 服务启动 mongodb-community
This should start the Mongo server. Run the Mongo shell, with the Mongo daemon running in one terminal, type mongoin another terminal window. This will run the Mongo shell which is an application to access data in MongoDB. To exit the Mongo shell run quit() To stop the Mongo daemon hit ctrl-c
这应该启动 Mongo 服务器。运行 Mongo shell,在一个终端中运行 Mongo 守护进程,在另一个终端窗口中输入mongo。这将运行 Mongo shell,它是一个用于访问 MongoDB 中数据的应用程序。退出 Mongo shell 运行 quit() 停止 Mongo 守护进程点击 ctrl-c
start service:
启动服务:
brew services start mongo
酿造服务启动mongo
https://treehouse.github.io/installation-guides/mac/mongo-mac.html
https://treehouse.github.io/installation-guides/mac/mongo-mac.html
回答by bello hargbola
To startrun brew services start [email protected]
要开始运行brew services start [email protected]
To endrun brew services stop [email protected]
要结束运行brew services stop [email protected]
回答by Neeraj Soni
Use this line it will fix the issue.
使用此行将解决问题。
Execute this line in your terminal at the mongo bin path:
在终端中的 mongo bin 路径中执行此行:
export PATH=<mongodb-install-directory>/bin:$PATH
<mongodb-install-directory>
replace this with your path, for example:
<mongodb-install-directory>
将其替换为您的路径,例如:
export PATH=/Application/Mongo/bin:$PATH