Mongo(3.6.2) cannot be started on mac terminal

  mongodb, question

[Problem]
MongoDB is used for the first time. It is installed but cannot be accessed through the terminal.
After searching for relevant information, I don’t know where the problem is.

I hope someone can give me a little advice. I am very grateful.

[Environment]
Terminal: mac os
MongoDB:3.6.2

[Relevant Code]

Sign in to MongoDB

himiMacBookPro:bin himi$ sudo mongod --port 27017 --dbpath /data/db

Or ..

himiMacBookPro:bin himi$ sudo mongod

Mac’s $path is set

Please get the following

2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] MongoDB starting : pid=24899 port=27017 dbpath=/data/db 64-bit host=himiMacBookPro.local
 2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] db version v3.6.2
 2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
 2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 0.9.8zc 15 Oct 2014
 2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] allocator: system
 2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] modules: none
 2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten] build environment:
 2018-02-12T21:01:38.228+0900 I CONTROL  [initandlisten]     distarch: x86_64
 2018-02-12T21:01:38.229+0900 I CONTROL  [initandlisten]     target_arch: x86_64
 2018-02-12T21:01:38.229+0900 I CONTROL  [initandlisten] options: { net: { port: 27017 }, storage: { dbPath: "/data/db" } }
 2018-02-12T21:01:38.229+0900 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
 2018-02-12T21:01:38.229+0900 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=7680M,session_max=20000,eviction=(threads_min=4,  threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),  file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
 2018-02-12T21:01:38.701+0900 I STORAGE  [initandlisten] WiredTiger message [1518436898:701666][24899:0x7fff75831300], txn-recover: Main recovery loop: starting at 6/4864
 2018-02-12T21:01:38.826+0900 I STORAGE  [initandlisten] WiredTiger message [1518436898:826287][24899:0x7fff75831300], txn-recover: Recovering log 6 through 7
 2018-02-12T21:01:38.921+0900 I STORAGE  [initandlisten] WiredTiger message [1518436898:921309][24899:0x7fff75831300], txn-recover: Recovering log 7 through 7
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten]
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten]
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server.
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
 2018-02-12T21:01:39.125+0900 I CONTROL  [initandlisten]
 2018-02-12T21:01:39.131+0900 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
 2018-02-12T21:01:39.131+0900 I NETWORK  [initandlisten] waiting for connections on port 27017

It will stay here for a long time.
According to theory, after this comes out, you should enter mongo.

But after a long time, the following will appear

2018-02-12T21:06:39.153+0900 I STORAGE  [thread1] createCollection: config.system.sessions with generated UUID: c16f1163-15d8-4132-8a66-5a2e61d855b1
 2018-02-12T21:06:39.238+0900 I INDEX    [thread1] build index on: config.system.sessions properties: { v: 2, key: { lastUse: 1 },   name: "lsidTTLIndex", ns: "config.system.sessions", expireAfterSeconds: 1800 }
 2018-02-12T21:06:39.238+0900 I INDEX    [thread1]      building index using bulk method;  build may temporarily use up to 500 megabytes of RAM
 2018-02-12T21:06:39.260+0900 I INDEX    [thread1] build index done.  scanned 0 total records. 0 secs
 2018-02-12T21:06:39.262+0900 I COMMAND  [thread1] command config.$cmd command: createIndexes { createIndexes: "system.sessions",   indexes: [ { key: { lastUse: 1 }, name: "lsidTTLIndex", expireAfterSeconds: 1800 } ],   $db: "config" } numYields:0 reslen:98 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { W: 1 } }, Collection: { acquireCount: { w: 1 } } } protocol:op_msg 115ms

Then there is nothing else.
There was no change after waiting for half an hour.

↓ If control+c occurs while waiting above, the following will appear

^C2018-02-12T22:04:41.601+0900 I CONTROL  [signalProcessingThread] got signal 2 (Interrupt: 2), will terminate after current cmd ends
 2018-02-12T22:04:41.601+0900 I NETWORK  [signalProcessingThread] shutdown: going to close listening sockets  ...
 2018-02-12T22:04:41.601+0900 I NETWORK  [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
 2018-02-12T22:04:41.603+0900 I FTDC     [signalProcessingThread] Shutting down full-time diagnostic data capture
 2018-02-12T22:04:41.605+0900 I STORAGE  [signalProcessingThread] WiredTigerKVEngine shutting down
 2018-02-12T22:04:41.803+0900 I STORAGE  [signalProcessingThread] shutdown: removing fs lock  ...
 2018-02-12T22:04:41.805+0900 I CONTROL  [signalProcessingThread] now exiting
 2018-02-12T22:04:41.805+0900 I CONTROL  [signalProcessingThread] shutting down with code:0

With other seemingly relevant orders, it is not clear what this represents.

himiMacBookPro:~ himi$ sudo /usr/local/mongodb/bin/mongod
 2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] MongoDB starting : pid=24718 port=27017 dbpath=/data/db 64-bit host=himiMacBookPro.local
 2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] db version v3.6.2
 2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
 2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 0.9.8zc 15 Oct 2014
 2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] allocator: system
 2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] modules: none
 2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] build environment:
 2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten]     distarch: x86_64
 2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten]     target_arch: x86_64
 2018-02-12T20:31:44.076+0900 I CONTROL  [initandlisten] options: {}
 2018-02-12T20:31:44.078+0900 I STORAGE  [initandlisten] exception in initAndListen: DBPathInUse: Unable to lock the lock file: /data/db/  mongod.lock (Resource temporarily unavailable). Another mongod instance is already running on the /data/db directory, terminating
 2018-02-12T20:31:44.078+0900 I CONTROL  [initandlisten] now exiting
 2018-02-12T20:31:44.078+0900 I CONTROL  [initandlisten] shutting down with code:100

[Find relevant materials by yourself]

http://www.runoob.com/mongodb …
http://blog.csdn.net/xht555/a …
https://stackoverflow.com/que …
https://www.jianshu.com/p/116 …

Mongod is the process of starting the database, not mongo. actually, the database has already been started. you just need to open another terminal and enter mongo.

Mongo is a mongodb management tool, mongod is a mongodb database process.