這篇文章給大家分享的是有關(guān)MongoDB數(shù)據(jù)庫怎么安裝的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
創(chuàng)新互聯(lián)建站是一家專注于成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)與策劃設(shè)計,鄂州網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:鄂州等地區(qū)。鄂州做網(wǎng)站價格咨詢:13518219792
1.下載mongodb系統(tǒng)包
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.4.tgz
2.解壓壓縮包
tar -zxvf mongodb-linux-x86_64-rhel70-3.2.4.tgz
3.將解壓包改名為/usr/local/下的mongodb
mv mongodb-linux-x86_64-rhel70-3.2.4 /usr/local/mongodb
4.創(chuàng)建數(shù)據(jù)庫目錄
cd /usr/local/mangodb/bin
mkdir -p data/test/db
mkdir -p data/test/logs
5.創(chuàng)建配置文件 mongodb.conf
vi mongodb.conf
dbpath = /usr/local/mongodb/bin/data/test/db
logpath = /usr/local/mongodb/bin/data/test/logs/mongodb.log
port = 27017
fork = true
nohttpinterface = true
6.啟動mongodb
./mongod –f mongodb.conf
7.查看 mongodb 進程:
ps -ef|grep mongodb
[root@localhost ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.4.tgz
--2018-08-26 18:17:12-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.4.tgz
Resolving fastdl.mongodb.org (fastdl.mongodb.org)... 54.230.249.222, 54.230.249.122, 54.230.249.63, ...
Connecting to fastdl.mongodb.org (fastdl.mongodb.org)|54.230.249.222|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 63674272 (61M) [application/x-gzip]
Saving to: ‘mongodb-linux-x86_64-rhel70-3.2.4.tgz’
100%[========================================================>] 63,674,272 3.36MB/s in 31s
2018-08-26 18:17:45 (1.93 MB/s) - ‘mongodb-linux-x86_64-rhel70-3.2.4.tgz’ saved [63674272/63674272]
[root@localhost ~]# tar -zxvf mongodb-linux-x86_64-rhel70-3.2.4.tgz
[root@localhost ~]# mv mongodb-linux-x86_64-rhel70-3.2.4 /usr/local/mongodb
[root@localhost mongodb]# cd bin
[root@localhost bin]# mkdir -p data/test/db
[root@localhost bin]# mkdir -p data/test/logs
[root@localhost bin]# vi mongodb.conf
dbpath = /usr/local/mongodb/bin/data/test/db
logpath = /usr/local/mongodb/bin/data/test/logs/mongodb.log
port = 27017
fork = true
nohttpinterface = true
[root@localhost bin]# ./mongod -f mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 11487
child process started successfully, parent exiting
[root@localhost bin]# ./mongo
> use DATABASE_NAME
如果數(shù)據(jù)庫不存在,則創(chuàng)建數(shù)據(jù)庫,否則切換到指定數(shù)據(jù)庫。
> use kingscc
switched to db laoA
> show dbs ( 查看都有什么數(shù)據(jù)庫,里面沒有數(shù)據(jù)的數(shù)據(jù)庫不顯示)
local 0.000GB
> db(顯示當(dāng)前的數(shù)據(jù)庫)
kingscc
> db.laoA.insert({"name":"kingscc丶"})(往數(shù)據(jù)庫插入數(shù)據(jù))
WriteResult({ "nInserted" : 1 })
> db.dropDatabase() (首先先使用數(shù)據(jù)庫,在進行刪除)
刪除當(dāng)前數(shù)據(jù)庫,默認(rèn)為 test,你可以使用 db 命令查看當(dāng)前數(shù)據(jù)庫名。
感謝各位的閱讀!關(guān)于“MongoDB數(shù)據(jù)庫怎么安裝”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!