1. Download MongoDB
wget http://downloads.mongodb.org/linux/mongodb-linux-i686-2.4.9.tgz
( you can go to the official website to download http://www.MongoDB.org/downloads)
2.unzip the MongoDB tar Zxvfmongodb-linux-i686-2.4.9. tgz
3. Create the specified folder and copy the MongoDB to the past mkdir-p/usr/local/MongoDB CP-R mongodb-linux-i686-2.4.9/*/usr/local/mongodb/
4. Create a database hosting directory and log storage filesMkdir-p/data/mongo/data Touch/data/mongo/dblogs
5. Start Mongod/usr/local/mongodb/bin/mongod--dbpath=/data/mongo/data--logpath=/data/mongo/dblogs--logappend--fork (//--fork is for the program to be executed in the background)6. Set up boot from bootEcho/usr/local/mongodb/bin/mongod--dbpath=/data/mongo/data--logpath=/data/mongo/dblogs--logappend--fork > >/etc/rc.local7. Close the Mongod process:
Pkill MongodCommon parameter descriptions for startup commands:--DBPATH Specifies the directory where the database file resides--port specifies the port default 27017--fork settings used by the Mongod service MONGO service for background run--logpath Specify the log file directory and the file name--logappend is set every time log is added at the end of the file--journal enable log--pidfilepath Specify the path of the process file, if not specified, the system will not produce the maximum number of concurrent connections to the process--maxconns --noprealloc turn off the pre-distribution of data files--rest Close the Rest API feature--nohttpinterface turn off Web management features--auth specify MONGO use authentication mechanism --BIND_IP Binding IP
MongoDB Basic Commands
*View Database
Show DBS | show databases;
* View Current database
db | Select Database ();
* CREATE DATABASE
Use test1 | CREATE DATABASE Test1
Note that it is not possible to show DBS in this time. An empty database needs to add at least one file Db.movie.insert ({"Test": "Test"})
* Switch Database
Use test1 | use test1
* Delete Database
Enter Database Db.dropdatabase | Drop database Test1
* Create a table
Db.xxx.insert () Call document | CREATE TABLE xxx;
*Check Table
Db.xxx.find or FindOne | select * FROM XXXX
Installing MongoDB under Linux