1、启动mongodb
/usr/local/mongodb/bin/mongod --dbpath /var/mongodb/data/
--logpath /var/mongodb/logs/log.log &
在mongodb启动命令中
--dbpath 指定mongodb的数据存储路径
--logpath 指定mongodb的日志存储路径
2、停止mongodb
第一步先进入mongo命令行模式
第二步,使用use admin 命令进入admin数据库
第三步,执行 db.shutdownServer()命令 停止服务。代码及显示如下:
[root@localhost data]# mongo
MongoDB shell version: 2.4.14
connecting to: test
Server has startup warnings:
2019-06-20T17:59:54.575+0800 I STORAGE [initandlisten]
2019-06-20T17:59:54.575+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-06-20T17:59:54.575+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten]
2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-06-20T17:59:55.404+0800 I CONTROL [initandlisten]
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** WARNING: You are running on a NUMA machine.
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** We suggest launching mongod like this to avoid performance problems:
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** numactl --interleave=all mongod [other options]
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-06-20T17:59:55.405+0800 I CONTROL [initandlisten]
> use admin
switched to db admin
> db.shutdownServer()
Thu Jun 20 18:01:16.276 DBClientCursor::init call() failed
server should be down...
Thu Jun 20 18:01:16.277 trying reconnect to 127.0.0.1:27017
Thu Jun 20 18:01:16.277 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
>
2 、导出Mongodb数据
[root@localhost back-mongo]# mongoexport -h 127.0.0.1:27017 -d trail -c location -o /home/back-mongo/show.csv
mongoexport用于导入csv或json或txt数据, 其中-h指定Mongo服务地址,-d指定导出哪个数据为,-c指定导出哪个表,-o指定导出的文件夹