Python -- first knowledge of database

1, Database overview

1. Why use a database

  1. If the data is stored in a file, reading and writing occupy disk IO, and the efficiency is low
  2. Data security considerations
  3. Support high concurrency

2. Database classification

At present, databases can be divided into two categories: relational databases and non relational databases

2.1 relational database (RDBMS)

Explanation: the relational database model is to reduce the complex data structure to a simple binary relationship (i.e. in the form of two-dimensional table, not excel, but very similar to excel). Combined with the following figure,

These tables establish a certain relationship and share the data of both sides. This is the relationship. This is similar when storing data in a relational database

2.2 non relational database

Non relational database is also called NoSQL database. NoSQL originally means "not old SQL"

  • It refers to non relational database, not "No SQL". Therefore, the production of NoSQL is not to completely deny relational database, but as an effective supplement to traditional relational database. NoSQL database can play an unimaginable high efficiency and high performance in specific scenarios.

  • With the development of internet web2 In the week of 0 website, the traditional relational database is dealing with web2,0 websites, especially for the expanding massive data, super large-scale and highly concurrent microblog, wechat and SNS web2 0 pure dynamic website has been inadequate, exposing many insurmountable problems.

  • For example, the IO bottleneck and performance bottleneck of traditional relational database are difficult to effectively break through, so there are a large number of database products with specific functions for specific scenarios and for the purpose of high performance and convenient use. NOSQL (non relational) data is born in this scenario and has developed very rapidly

  1. High performance, high concurrency and low requirements for data consistency
  2. The open source NoSQL system, such as Facebook's Cassandra and Apache's HBase, has also been widely recognized. Redis and mongb have gradually been welcomed and pursued by all kinds of large, medium and small companies

NOSQL non relational database summary:
3. NOSQL is not a negation of relational database, but an important supplement to relational database
4. NOSQL is born for high performance and high concurrency, ignoring the functions that affect high performance and high concurrency
5. Typical NoSQL products memcached (pure memory), redis (persistent cache), mongodb (document database)

Non relational database classification

(1)Key value( Key-Value)Storage database
The key value database is similar to the hash table used in traditional languages key To add, query, or delete data because key Primary key access, so it will obtain high performance and scalability 
        Key value( Key-Value)The database mainly uses a hash table, which has a specific key and a pointer to specific data. Key/value Model for IT The advantage of the system lies in its simplicity, easy deployment and high concurrency 
        Typical products: Memcached,Redis,MemcacheDB,BerkeleyDB 

(2)Column storage( Column-oriedted)database ======>It's enough to understand. It's usually not used by companies 
         This part of the database is usually used for distributed storage of massive data. The keys still exist, but their feature is that they point to multiple columns. 
        Typical products: Cassandra,HBase 

(3)Document oriented( Document-Oriented)database
        The document oriented database will be stored as a document. Each document is a self-contained data unit and a collection of a series of data items.
        Each data item has a name and corresponding value. The value can be a simple data type, such as string, number, date, etc; It can also be complex types, such as sequence tables and relational objects.
        The smallest unit of data storage is the document. The document attributes stored in the same table can be different, and the data can be used XML,JSON perhaps JSONB And other forms of storage 
        Typical products: MorgoDB,CouchDB 

(4)Graphics( Graph)database

Introduction to common non relational databases

 2.2.1  memcached(key-value)

  Memcaced It is an open source, high-performance cache system with distributed memory objects. It can lighten the load of database and accelerate the dynamic web Application, original version by LiveJoumal of Brad Fitzpatrick It was developed and completed in 2003. At present, many users all over the world are using it to build a large load website of the host or improve the response speed of the high access website of the host. be careful: Memcache Is the name of the project, and Memcached Is the main program file name of the server. 
Cache is generally used to store the objects or data accessed by some processes. Accessing objects or data through cache is much more than accessing blocks on disk. The former is memory, the latter is disk Memcached Is a pure memory cache system, which caches frequently accessed objects or data in memcached In memory, these cached data are passed by the program API Is read in the same way, memcached The data inside is like a huge picture hash Table, data in key-value The right way exists. Memcached By caching frequently accessed objects or data, we can reduce the pressure of frequently reading the database, improve the response speed of the website, and build a fast, faster and scalable database Web Application. 
  Official website: 
  because memcached It is a pure memory cache software. Once restarted, all data will be lost. Therefore, is based on Memcached Developed an open source project Memcachedb. Pass for Memcached increase Berkeley DB The special long-term storage mechanism and asynchronous primary replication mechanism make Memcached With transaction recovery capability, persistent data capability and distributed replication capability, memcached It is very suitable for application scenarios requiring ultra-high performance read-write speed and persistent storage, but it has been gradually replaced by other persistent products in recent years, such as Redis

  Memcached Summary: 
  1,key-value Row database 
  2,Pure memory database 
  3,Persistence memcachedb(sina)

2.2.2  Redis(key-value)

        and Memcached similar, redis Also a key-value Type storage system. but redis Supported storage value There are relatively more types, including string(String) list(Linked list) set(Set) and zset(Ordered set), etc. These data types are supported push/pop,add/remove And take intersection, union and difference sets and richer operations, and these operations are atomic. To ensure efficiency, redis All data is cached in memory. The difference is redis It will periodically write the updated data to the disk or write the modification operation to the additional record file, and it is realized on the basis of master-slave(Master slave) synchronization. 

  redis Is a high-performance key-value database redis The emergence of, to a great extent, compensated memcached This kind key/value The lack of storage can play a good supplementary role to relational database in some occasions. It provides Python,Ruby,Erlang,PHP Client, easy to use. 
  redis characteristic: 
  1)Support memory caching, which is equivalent to memcached 
  2)Support persistent storage, which is equivalent to memcachedb,ttserver 
  3)Richer database types. Than others key-value More powerful library 
  4)Support master-slave cluster and distributed 
  5)Support queue and other special functions 
  Application: cache access from memcached Change access redis

2.2.3  MongoDB(Document-oriented)

  MongoDB It is a product between relational database and non relational database. It is the most functional and relational database among non relational databases. The database structure he supports is very loose and similar json of bjson Format, so you can store more complex data types. Mongodb The biggest feature is that the query language he supports is very powerful. Its syntax is a bit similar to the object-oriented query language. It can almost realize most functions similar to the single table query of relational database, and also support the establishment of index on data. 

    High performance, easy to deploy, easy to use and convenient to store data 
  Main functional features: 

    1.For collection storage, it is easy to store data of object type 
    2."Set oriented( Collenction-Orented)It means that the database is grouped and stored in a data set, which is called a collection( Collenction)Each collection has a unique identification name in the database and can contain an unlimited number of documents. The concept of collection is similar to that of relational database( RDBMS)Watch in( table)The difference is that it does not need to define any schema( schema) 
    3.Mode freedom 
      Mode freedom( schema-free)Means stored in mongodb We don't need to know any structure definition of the file in the database. 
    4.Support dynamic query 
    5.Supports full indexing, including internal objects 
    6.Support query 
    7.Support replication and failover 
    8.Use efficient binary data storage, including large objects 
    9.Automatically process fragments to support the scalability of cloud computing hierarchy
2.2.4  Cassandra(Column-oriented)

  Apache Cassndra Is an open source distributed Key-Value Storage system. It was originally created by Facebook Developed to store particularly large data. Facebook This system is currently in use. 
Main features: 

  1.Distributed based on column Structured 
  3.High extensibility 
  4.Cassandra The main feature of is that it is not a database, but a distributed network service composed of a bunch of database nodes Cassandra A write operation of will be copied to other nodes, right Cassandra Read operation. It will also be routed to a node to read. 
  Cassandir Is a hybrid non relational database, similar to Google of BigTable. Its main function ratio Dynomie(Distributed key-value More storage systems, Cassandra Initially by Facebook After development, it was transformed into an open source project.

2.2.5  Other infrequently used non relational databases

  HBase,MemcacheDB,BerkeleyDB,Tokyo Cabinet\Tokyo Tyrant(ttserver) 
  ttserver Persistent output, with the disadvantage of storing 20 million entries, and the performance is reduced (invented by the Japanese)

Keywords: Python

Added by dilum on Thu, 17 Feb 2022 14:34:09 +0200