1.官网下载压缩包,并解压到当地任一目录。(我的是Documents/develop/mongodb)
2.在mongodb下新建data文件夹,在data下新建db文件夹。(bin和data文件夹在一级)
3.进入bin文件夹,并设置数据库数据存放的地址变量
cd Documents/develop/mongodb/bin
./mongod --dbpath /Users/wangming/Documents/develop/mongodb/data/db
出现以下提示
2014-09-24T09:26:11.776+0800 [initandlisten] MongoDB starting : pid=1229 port=27017 dbpath=/Users/wangming/Documents/develop/mongodb/data/db 64-bit host=wangmingdeMacBook-Pro.local 2014-09-24T09:26:11.776+0800 [initandlisten] 2014-09-24T09:26:11.776+0800 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 2014-09-24T09:26:11.776+0800 [initandlisten] db version v2.6.4 2014-09-24T09:26:11.776+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910 2014-09-24T09:26:11.777+0800 [initandlisten] build info: Darwin bs-osx108-4 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49 2014-09-24T09:26:11.777+0800 [initandlisten] allocator: system 2014-09-24T09:26:11.777+0800 [initandlisten] options: { storage: { dbPath: "/Users/wangming/Documents/develop/mongodb/data/db" } } 2014-09-24T09:26:11.785+0800 [initandlisten] journal dir=/Users/wangming/Documents/develop/mongodb/data/db/journal 2014-09-24T09:26:11.785+0800 [initandlisten] recover : no journal files present, no recovery needed 2014-09-24T09:26:11.800+0800 [FileAllocator] allocating new datafile /Users/wangming/Documents/develop/mongodb/data/db/local.ns, filling with zeroes... 2014-09-24T09:26:11.800+0800 [FileAllocator] creating directory /Users/wangming/Documents/develop/mongodb/data/db/_tmp 2014-09-24T09:26:11.829+0800 [FileAllocator] done allocating datafile /Users/wangming/Documents/develop/mongodb/data/db/local.ns, size: 16MB, took 0.029 secs 2014-09-24T09:26:11.899+0800 [FileAllocator] allocating new datafile /Users/wangming/Documents/develop/mongodb/data/db/local.0, filling with zeroes... 2014-09-24T09:26:12.075+0800 [FileAllocator] done allocating datafile /Users/wangming/Documents/develop/mongodb/data/db/local.0, size: 64MB, took 0.176 secs 2014-09-24T09:26:12.193+0800 [initandlisten] build index on: local.startup_log properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "local.startup_log" } 2014-09-24T09:26:12.194+0800 [initandlisten] added index to empty collection 2014-09-24T09:26:12.194+0800 [initandlisten] command local.$cmd command: create { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 numYields:0 reslen:37 394ms 2014-09-24T09:26:12.194+0800 [initandlisten] waiting for connections on port 27017 2014-09-24T09:26:23.841+0800 [initandlisten] connection accepted from 127.0.0.1:50778 #1 (1 connection now open) 2014-09-24T09:26:23.841+0800 [conn1] end connection 127.0.0.1:50778 (0 connections now open) 2014-09-24T09:26:23.994+0800 [initandlisten] connection accepted from 127.0.0.1:50780 #2 (1 connection now open) 2014-09-24T09:26:23.994+0800 [conn2] end connection 127.0.0.1:50780 (0 connections now open) 2014-09-24T09:27:11.814+0800 [clientcursormon] mem (MB) res:33 virt:2653 2014-09-24T09:27:11.814+0800 [clientcursormon] mapped (incl journal view):160 2014-09-24T09:27:11.814+0800 [clientcursormon] connections:0 2014-09-24T09:28:13.996+0800 [initandlisten] connection accepted from 127.0.0.1:50789 #3 (1 connection now open) 2014-09-24T09:32:11.887+0800 [clientcursormon] mem (MB) res:33 virt:2653 2014-09-24T09:32:11.887+0800 [clientcursormon] mapped (incl journal view):160 2014-09-24T09:32:11.887+0800 [clientcursormon] connections:1 2014-09-24T09:37:11.960+0800 [clientcursormon] mem (MB) res:33 virt:2653 2014-09-24T09:37:11.960+0800 [clientcursormon] mapped (incl journal view):160 2014-09-24T09:37:11.960+0800 [clientcursormon] connections:1
4.command+T新建一个终端窗口,在bin文件下输入./mongo指令
MongoDB shell version: 2.6.4 connecting to: test Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user Server has startup warnings: 2014-09-24T09:26:11.776+0800 [initandlisten] 2014-09-24T09:26:11.776+0800 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
至此,ok了。