In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Recently, there is a functional module of a project that needs to manipulate collection-type data and other reasons for ease of processing. After much consideration, I finally decided to give up using MySQL and choose MongoDB instead.
The two databases should be no stranger to everyone. The biggest difference between them is that MySQL is a relational database while MongoDB is a non-relational database. The common relational databases are MySQL, Oracle, DB2, SQL Server, Postgre SQL and so on, while the non-relational databases are MongoDB, Redis, Memcached, HBse and so on.
1 Relational database? Non-relational database?
A relational database can be understood as a database that relies on a model to create. For example, the table in our MySQL is a two-dimensional table consisting of horizontal and vertical columns. Relational database can associate the data of multiple tables through relational model, such as one-to-one, one-to-many, many-to-one. Because it is based on the data model, we can easily do complex query operations among multiple tables through SQL statements. Relational database is relatively safe, because it is directly stored in the hard disk, so sudden outages, power outages and other accidents will not lead to data loss. The storage mode of MySQL is determined by its own engine, and the commonly used engines are Innodb and MyISAM. The main difference between them is that MyISAM does not support transactions and emphasizes performance, which is faster than Innodb. Innodb provides advanced database functions such as supporting transactions.
Non-relational database, which is what we often call NoSQL database, is relatively simple to deploy and is not as complex as relational database. The storage mode of Mongo is virtual memory + persistent storage. Mongo writes the data to memory, and then the virtual memory manager persists it to the hard disk, so the write operation is much faster than the relational database. The storage format of NOSQL is in the form of key-value, which can store data of basic data types like relational databases, as well as collections, objects, and so on. Although NoSQL has high performance, it does not support things and cannot query linked tables, so it is generally used for large-scale data storage.
2 what are their advantages and disadvantages
Relational database has been developed for a long time and has a very mature system. The share is also gradually increasing. Moreover, it supports the operation of things, ensures the consistency of data, and can complete complex operations through SQL statements. However, in the process of use, when the amount of data reaches a certain extent, the efficiency of relational database will decrease significantly. In a complex query operation, a series of combined indexes will consume a lot of memory space, so we need to separate read and write operations on the database, or split the database structure (horizontal split, vertical split) to share the request pressure in different libraries.
Vertical split refers to splitting a table into multiple tables, which are associated with each other through a primary key.
Horizontal split is split into multiple tables according to certain rules, such as split by user roles
Read-write separation: the so-called read-write separation means that read operations (query data) and write operations (insert & update) point to different database nodes, and they synchronize data through some mechanism, such as binlog. In practical applications, most of the pressure still comes from the read operation, so it is mainly an one-master and multi-slave architecture.
With the development of non-relational database in recent years, it is deeply loved by people. Obvious advantages such as free open source, low cost, simple deployment, unstructured storage and so on. And it has a very strong ability to deal with massive data, memory-level database, query speed is also very fast. The stored data format is rich and easy to expand, although sql can not be used for complex queries, but MongoDB supports JavaScript, so complex database management operations can be carried out through js scripts. With regard to the shortcomings of NoSQL, I feel that I don't support things at the moment, and it doesn't matter in other ways.
3 when to use mongo
Mongo is written in C++ and supports many languages such as Java, Python, Ruby, PHP, C++, C# and so on. Sometimes for different business needs, choosing Mongo can avoid wasting a lot of unnecessary resources.
Log system
The log information generated during the operation of the system is generally of many kinds, wide range and messy content. These messy logs can be collected and managed through MongoDB. Not only is it easy to manage, but it is also very easy to find or export.
Geolocation storage
MongoDB supports geographical location, two-dimensional spatial index, can store latitude and longitude, so it can quickly calculate the distance between two points, and other location information. Such as inquiring about nearby people, or booking system, distribution system, etc.
The scale of data is growing rapidly.
As mentioned earlier, when the amount of data in a relational database is too large, it is necessary to divide the database and table, which may be troublesome to operate. If you choose mongo for sub-library and sub-table operation, it will become very simple.
Ensure a highly available environment
Mongo itself has a highly available and partitioned solution, and it is very convenient to set up master and slave servers. In addition, Mongo can also quickly and safely realize the transfer of failed nodes.
File storage requirements
GridFS is a MongoDB specification for storing and retrieving large files such as pictures, audio, video, and so on. Although GridFS is a way of file storage, it can store more than 16m files. But it itself is stored in the MongoDB collection
Other scenes
For example, in game development, we can store user information, equipment, points and so on through MongoDB. In addition, logistics systems, social systems, and even Internet of things systems, Mongo can provide perfect data storage services.
4 simple performance testing of MySQL and MongoDB
With regard to the performance of the two data, the most powerful words are tested through practice. I see a set of test data on the Internet and share them with you.
Test environment: Windows 10, 8G memory, CPU i5 3.30GHZ. All have no index
Test language: Python
Link tools: pymysql, pymongo
MySQL & & Mongo Test data Statistics
Number of submissions per submission MySQL run time (s) Mongo run time (s) number of data 110001039121622.0202100301.61100031005.771.600410252.351.560510257.421.601000000 6100001298.075.2907100001496.185.2910 million
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.