search
HomeDatabaseMysql TutorialMongoDB(二)安装配置了解

MongoDB(二)安装配置了解

Jun 07, 2016 pm 04:10 PM
mongodblearnInstallConfiguration

前边介绍了MongoDB的大概理论知识,这篇来对MongoDB进行一下安装使用,支持安装在windows和linux上,当然了更多情况下我们是安装在linux上,因为毕竟服务器用linux的还是主流,当然了对于不同的系统,MongoDB的安装使用等其实都基本相同的,所以不用太在意这

前边介绍了MongoDB的大概理论知识,这篇来对MongoDB进行一下安装使用,支持安装在windows和linux上,当然了更多情况下我们是安装在linux上,因为毕竟服务器用linux的还是主流,当然了对于不同的系统,MongoDB的安装使用等其实都基本相同的,所以不用太在意这个,我们学习在那个平台上都是可以的。好,下载MongoDB:http://www.mongodb.org/downloads,根据我们的需要进行安装。

1,解压安装:将下载好的MongoDB解压到想要安装的路径下即可,例如:d:\mongodb


2,建文件夹:建立数据存放文件夹,例如:d:\mongodb\data\db;建立日志存放文件夹,例如:d:\mongodb\log\mongodb.log。(根据实际情况而定,不是固定的,只要有存放数据和日志的文件夹即可)


3,Win+R进入“运行”输入cmd,进入dos窗口,cd命令进入d:\mongodb\bin下,然后运行:mongod --dbpath"d:\mongodb\data\db\" --logpath "d:\mongodb\log\mongodb.log,即可运行mongodb服务。注意,mongod,dbpath,logpath几个关键字。这里我们都可以查看bin下的命令,我们用的都是这些,通过“命令-help”进行查看其参数即可。


4,进入数据库:mongodb的默认端口是27017,直接使用mongo命令即可进入数据库。然后进行各种database,collection,document进行增删改查的操作。但是这里的命令窗口不能关闭,要不mongodb的服务将停止。


5,让服务随电脑启动一起启动,在dos窗口中输入:

mongod --dbpath "d:\mongodb\data\db" --logpath"d:\mongodb\data\log\mongodb.log" --install --serviceName"MongoDB"

英文翻译也可以看出,是将这个启动mongodb的服务命令,加载到电脑服务中,服务名字叫做"MongoDB"。

然后启动即可:NET START MongoDB

6,关闭MongoDB服务,并关闭随机启动:

NET stop MongoDB (关闭服务)

mongod --dbpath"d:\mongodb\data\db" --logpath "d:\mongodb\data\log\mongodb.log" --remove--serviceName "MongoDB"

好,这样就算基本完成了,当然linux中和这也是一样的,最起码bin下的命令是通用的,需要我们的是掌握一些linux的操作命令才行。

看一下常用命令:

  • show dbs 显示数据库列表
  • use dbname 进入dbname数据库,大小写敏感,没有这个数据库也不要紧
  • show collections 显示数据库中的集合,相当于表格

    对于数据库的增删改查及其命令,下篇简单介绍。剩下简单看一下MongoDB的体系架构,看一张图吧,感觉挺清楚明了:

    \


    喎?http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD48cD4gICAgwO+x37/J0tS05rXEyv2+3cDg0M2jujwvcD48dWwgdHlwZT0="disc">

  • null null用于表示空值或者不存在的字段。 {"x":null}
  • 布尔 布尔类型有两个值'true'和'false1'. {"X":true}
  • 32位整数 类型不可用。JavaScript仅支持64位浮点数,所以32位整数会被自动转换。
  • 64位整数 不支持这个类型。shell会使用一个特殊的内嵌文档来显示64位整数,
  • 64位浮点数 shell中的数字都是这种类型。下面的表示都是浮点数: {"X" : 3.1415926} {"X" : 3}
  • 字符串 UTF-8字符串都可表示为字符串类型的数据: {"x" : "foobar"}
  • 符号 不支持这种类型。shell将数据库里的符号类型转换成字符串。
  • 对象id 对象id是文档的12字节的唯一 ID, {"X" :ObjectId() }
  • 日期 日期类型存储的是从标准纪元开始的毫秒数。不存储时区: {"X" : new Date()}
  • 正则表达式 文档中可以包含正则表达式,采用JavaScript的正则表达式语法: {"x" : /foobar/i}
  • 代码 文档中还可以包含JavaScript代码:{"x" : function() { /* …… */ }}
  • 二进制数据 二进制数据可以由任意字节的串组成。不过shell中无法使用。
  • 最大值 BSON包括一个特殊类型,表示可能的最大值。shell中没有这个类型。
  • 最小值 BSON包括一个特殊类型,表示可能的最小值。shell中没有这个类型。
  • 未定义 文档中也可以使用未定义类型:{"x":undefined}
  • 数组 值的集合或者列表可以表示成数组:{"x" : ["a", "b", "c"]}
  • 内嵌文档 文档可以包含别的文档,也可以作为值嵌入到父文档中,数据可以组织得更自然些,不用非得存成扁平结构的:{"x" : {"food" : "noodle"}}

    当然了,为了更加方便的操作MongoDB,也提供了类似PL/SQLdeveloper(连接Oracle),Mysql Front,Navicat Premium 等连接数据库的工具,这里看下MongoVUE,很是不错,看一下界面:


    好,剩下我们就按照数据库思路学习把,什么增删改查,什么分布,负载均衡等等,看后边的总结。



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

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),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment