1、下载 MongoDB的官方下载站是http://www.mongodb.org/downloads 可以在上面下载最新的安装程序,在下载页面可以看到,它对操作系统支持很全面,如OS X、Linux、Windows、Solaris都支持,而且都有各自的32位和64位版本2.4.12版本。 下面将分别介绍Windows和
1、下载
MongoDB的官方下载站是http://www.mongodb.org/downloads 可以在上面下载最新的安装程序,在下载页面可以看到,它对操作系统支持很全面,如OS X、Linux、Windows、Solaris都支持,而且都有各自的32位和64位版本2.4.12版本。
下面将分别介绍Windows和Linux版本的安装方法。
2、Windows平台的安装
步骤一:下载MongoDB
url下载地址:http://www.mongodb.org/dr//fastdl.mongodb.org/win32/mongodb-win32-i386-2.6.6.zip/download
说明:在此演示安装下载使用windows xp 32位环境,建议不使用32位的环境。
步骤二:设置MongoDB程序存放目录
在C:\盘目录下新建名为mongodb文件夹,将MongoDB解压到至该目录下,然后在该目录下新建子目录data和logs目录。data目录用于存放mongodb的数据,logs目录用户存放mongodb的日志。
步骤三:配置环境变量
该步骤主要是为了命令行的方便使用,可以把C:\mongodb\bin加到系统环境变量的path中。
步骤四:启动MongoDB服务。
打开cmd控制台,执行如下操作即可启动MongoDB服务
说明:MongoDB服务端的默认监听端口是27017
步骤五:安装windows服务
执行如下操作:
此时可以查看windows的服务中出现了MongoDB的服务,如下图所示:
在cmd控制台中输入如下命令启动MongoDB服务,或者在windows服务中直接启动
步骤六:客户端连接验证
新打开一个cmd控制台,输入mongo,如果出现下面提示,那么就可以开始MongoDB之旅了。
步骤七:查看MongoDB日志
查看c:\mongodb\logs\mongodb.log文件,即可对MongoDB的运行情况进行查看或者排错了。
这样就完成了Windows平台的MongoDB安装演示。
3、Linux平台的安装
3.1、安装说明
系统环境:CentOS-6.4 64位
安装软件:mongodb-linux-x86_64-2.6.6.tgz
下载地址:http://www.mongodb.org/
上传位置:/usr/src/
安装目录:/usr/local/mongodb
数据位置:/var/mongodb/data
日志位置:/var/mongodb/logs
3.2、检查是否安装过mongodb
[root@localhost src]# rpm -qa|grep mongodb
[root@localhost src]# service mongodb status
mongodb: unrecognized service
3.3、安装mongodb
[root@localhost ~]# cd /usr/src [root@localhost src]# groupadd mongodb [root@localhost src]# useradd mongodb -g mongodb [root@localhost src]# tar -zxvf mongodb-linux-x86_64-2.6.6.tgz [root@localhost src]# mv mongodb-linux-x86_64-2.6.6 /usr/local/mongodb [root@localhost src]# cd /usr/local/ [root@localhost local]# chown -R mongodb:mongodb mongodb [root@localhost local]# cd mongodb/ [root@localhost mongodb]# mkdir /var/mongodb [root@localhost mongodb]# mkdir /var/mongodb/data [root@localhost mongodb]# mkdir /var/mongodb/logs [root@localhost mongodb]# service iptables stop//实【本文来自鸿网互联 (http://www.68idc.cn)】验环境中关闭防火墙 iptables: Flushing firewall rules: [ OK ] iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Unloading modules: [ OK ]
3.4、配置
添加CentOS开机启动项
[root@localhost mongodb]# vi + /etc/rc.d/rc.local
将mongodb启动命令脚本追加到文件中:
/usr/local/mongodb/bin/mongod --dbpath=/var/mongodb/data --logpath /var/mongodb/logs/log.log -fork
3.5、启动MongoDB
[root@localhost bin]# ./mongod --dbpath=/var/mongodb/data/ --logpath /var/mongodb/logs/log.log -fork
3.6、测试MongoDB
[root@localhost bin]# ./mongo MongoDB shell version: 2.6.6 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 >查看数据库列表
> show dbs admin (empty) local 0.078GB
切换数据库
> use admin switched to db admin添加用户
> db.addUser("xuzheng","123456",true); WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead Successfully added user: { "user" : "xuzheng", "roles" : [ "readAnyDatabase" ] }显示状态
> db.stats(); { "db" : "admin", "collections" : 4, "objects" : 11, "avgObjSize" : 82.9090909090909, "dataSize" : 912, "storageSize" : 32768, "numExtents" : 4, "indexes" : 3, "indexSize" : 24528, "fileSize" : 67108864, "nsSizeMB" : 16, "dataFileVersion" : { "major" : 4, "minor" : 5 }, "extentFreeList" : { "num" : 0, "totalSize" : 0 }, "ok" : 1 }
显示当前版本:
> db.version();
2.6.6
获取当前使用数据库:
> db.getMongo();
connection to 127.0.0.1
简单插入数据:
> db.user.insert({"name":"xuzheng",age:20});
WriteResult({ "nInserted" : 1 })
查看数据:
> db.user.find();
{ "_id" : ObjectId("549d085621fc93b35ccba9a0"), "name" : "xuzheng", "age" : 20 }
说明:以上仅仅只是简单演示下MongoDB最常用的基本操作,MongoDB默认情况下数据库监听端口为27017,如果要远程连接一个非服务,使用--port和--host来操作,如下图所示:当然前提是远程的机器上必须安装有mongodb的客户端工具也就是mongo服务。
至此,MongoDB在Windows平台和Linux平台的安装完成,由于不同的系统环境不一致,所以在其他平台中安装会出现一些问题,都可以从网上找到解决的办法,在此不依依演示。

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.

MySQL is not a programming language, but its query language SQL has the characteristics of a programming language: 1. SQL supports conditional judgment, loops and variable operations; 2. Through stored procedures, triggers and functions, users can perform complex logical operations in the database.

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is an open source relational database management system suitable for data storage, management, query and security. 1. It supports a variety of operating systems and is widely used in Web applications and other fields. 2. Through the client-server architecture and different storage engines, MySQL processes data efficiently. 3. Basic usage includes creating databases and tables, inserting, querying and updating data. 4. Advanced usage involves complex queries and stored procedures. 5. Common errors can be debugged through the EXPLAIN statement. 6. Performance optimization includes the rational use of indexes and optimized query statements.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

InnoDB's lock mechanisms include shared locks, exclusive locks, intention locks, record locks, gap locks and next key locks. 1. Shared lock allows transactions to read data without preventing other transactions from reading. 2. Exclusive lock prevents other transactions from reading and modifying data. 3. Intention lock optimizes lock efficiency. 4. Record lock lock index record. 5. Gap lock locks index recording gap. 6. The next key lock is a combination of record lock and gap lock to ensure data consistency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),