MySQL and MongoDB The difference between ?
Before we talk about relational databases and NoSQL Related concepts of
Relational database ：
Relational database (relationship database) A database in which the stored data format is structured data ,
RDB The data format in is a two-dimensional table structure . In this two-dimensional table structure , Data consists of rows and columns , A row of data represents a record . A list of contents , Represents an attribute of this line , Or field .
RDB The stored data format is structured data , When creating a table , Will define columns ( field ) Name and type of , Each record inserted into the table follows this definition , This approach brings reliability and stability （ However, it is difficult to modify these data ）.
But the grouping of each record field is the same , Even if not all fields are required for every record , But the database assigns all fields to each record , Such a structure can facilitate the connection between tables and other operations , But from another point of view, it is also a factor of relational database performance bottleneck .
With the rapid development of the Internet , Traditional relational database is dealing with super large scale , When the traffic is very large and the concurrency is high, I can't do it . And this is the moment ,Nosql It has been developed rapidly .
NoSQL(not only SQL)：
Is a general term for a class of databases , It's a distributed database .
Non relational database (NoSQL) Store by key value pair , Its structure is not fixed , It's a dynamic structure , Each record can have different fields （ The name or type can be different ）, Each record can add its own key value pairs as needed , This will not be limited to fixed structures , It can reduce the cost of time and space , It is easy to adapt to changes in data types and structures .
The common types of included databases are as follows ：
Object oriented database
Document oriented database ：MongoDB,CouchDB
Key value pair database :Redis
Column oriented database : Cassandra,Hbase,HyperTable
MySQL and MongoDB The difference between ?
It's relational (RDB） The stored data format is structured data ,RDB The data format in is a two-dimensional table structure , Such a structure can facilitate the connection between tables and other operations . In this two-dimensional table structure , Data consists of rows and columns , A row of data represents a record . A list of contents , Represents an attribute of this line , Or field .
yes NoSQL One of the classes , Yes no relational database , For document data without defining table structure , It has very fast processing speed , adopt BSON Can save and query any type of data . Unable to proceed JOIN handle , But it can be embedded (embed) To achieve the same function .
MySQL <> and MongoDB Both are free and open source databases .
MySQL and MongoDB There are many basic differences, including the representation of data (data
representation), query , relationship , affair ,schema Design and definition of , Standardization (normalization), Speed and performance .
By comparison MySQL and MongoDB, In fact, we are comparing relational and non relational databases .
In addition to the differences already described above , There are also the following differences ：
Storage specification ：
The data storage of relational database is more normative , Divide data into smallest relational tables to avoid duplication , Get streamlined space use . Although the management is very clear , But when a single operation is designed to multiple tables , Data management is a bit troublesome . and Nosql Data is stored in a flat dataset , Data can often be duplicated . Individual databases are rarely separated , It's stored as a whole , In this way, the whole data is easier to read and write .
Query methods ：
Relational database operates database through structured query language （ That's what we usually say SQL）.SQL Support database CURD The operation is very powerful , Is the industry standard usage . and Nosql Querying data in blocks , It uses unstructured query language （UnQl）, There is no standard for it . Corresponding primary key table in relational database Nosql For storing documents in ID.
Relational databases use predefined optimization methods （ For example, the index ） To speed up query operations , and Nosql It has simpler and more accurate data access mode .
Relational database follows ACID rule （ Atomicity (Atomicity), uniformity (Consistency), Isolation (Isolation), persistence (Durability)）, and Nosql Database compliance BASE principle （ Basically available （Basically
Availble）, soft / Flexible business （Soft-state ）, Final consistency （Eventual Consistency））.
Because of the strong data consistency of relational database , So the support for transactions is good . Relational database supports fine-grained control of transaction atomicity , And it is easy to roll back transactions . and Nosql The database is in CAP（ uniformity , usability , Partition tolerance ） Choose two of them , Because in the distributed system based on nodes , It's hard to satisfy all of them , So the support for transactions is not very good , Transactions can also be used , But it's not Nosql The flash point of .
Storage expansion ：
This is probably the biggest difference between the two , Relational database is vertical extension , That is to say, we want to improve the processing capacity , To use a faster computer . Because the data is stored in relational tables , Multiple operation tables may be involved in performance bottlenecks , It needs to be overcome by improving computer performance . Although there is a lot of room for expansion , But it will eventually reach the upper limit of vertical expansion . and Nosql The database is scale out , Its storage is naturally distributed , You can share the load by adding more normal database servers to the resource pool .
In order to maintain the consistency of data, relational database has paid a huge price , The reading and writing performance is poor . In the face of high concurrent read and write performance is very poor , In the face of massive data, the efficiency is very low . and Nosql The storage format is key-value Type , And stored in memory , Very easy to store , And for data
Consistency is Weak requirements .Nosql No need sql Analysis of , Improved read-write performance .