Database basics - 1. Database overview

From this article we start to learn about database knowledge

Table of contents

1. Why use a database

2. Database and database management system

2.1 Related concepts

2.2 Relationship between database and database management system

​Edit 2.3 Common database management systems

2.4 Common database introduction

3. MySQL introduction

3.1 Overview

3.2 About MySQL8.0

3.3 Oracle vs MySQL

4. RDBMS and non-RDBMS

4.1 Relational database (RDBMS)

4.1.1 Substance

4.1.2 Advantages

4.2 Non-relational databases (non-RDBMS)

4.2.1 Introduction

4.2.2 What are the non-relational databases

4.3 Summary

5 Relational Database Design Rules

5.1 Tables, records, fields

5.2 Relationship between tables

5.2.1 One-to-one association

5.2.2 One-to-many relationship

5.2.3 Many-to-many

5.3.4 Self reference 


1. Why use a database

The database is used because the database has the characteristics of data persistence

Persistence: storing data to a power-downable storage device for later use. In most cases, especially for enterprise-level applications, data persistence means saving the data in the memory to the hard disk for "solidification" , and the realization of persistence is mostlydone through various relational databases

The main function of persistence is to store the data in the memory into the relational database , of course, it can also be stored in the disk file and xml file

Explanation: Some of our usual data is stored in the memory, and the storage of data in the memory is realized by high and low voltages. Once we cut off the power, the data cannot be stored in the memory, that is to say, the data in the memory will disappear. , in order to avoid this problem, we use a database to store data. The database has the characteristics of persistence , and the data can be stored on a power-down storage device for later use.

2. Database and database management system

2.1 Related concepts

DB: Database (Database): the warehouse for storing data, its essence is a file system, which stores a series of organized data

Path: Find our MySQL installation path, enter the root directory, click on the "data" folder, which is the database

In fact, to put it bluntly, the database is our series of files, tables, and places for data. This place can be tables, folders, or other things.

DBMS: Database Management System (Database Management System): It is a large-scale software for manipulating and managing databases, used to establish, use and maintain databases, and perform unified management and control on databases. Users access the data in the tables in the database through the database management system.

This is the MySQL we use, and MySQL is the DBMS.

SQL: Structured Query Language (Structured Query Language) : A language designed to communicate with databases.

2.2 Relationship between database and database management system

A database management system (DBMS) can manage multiple databases, and a general developer will create a database for each application. In order to save the data of the entities in the application, multiple tables are generally created in the database to save the data of the entity users in the program.

The relationship between database management system, database and table is shown in the figure:

2.3 Common database management systems

At present, the common database management software on the Internet includes Oracle, MySQL, MS SQL Server, DB2, PostgreSQL, Access, Sybase, and Informix . The following are the statistical results of the survey on the popularity of each database:

(Check the latest ranking of the database: https://db-engines.com/en/ranking)

2.4 Common database introduction

Oracle

In 1979, Oracle 2 was born, it was the first commercial RDBMS (relational database management system). As Oracle software became more and more famous, the company changed its name to Oracle Corporation.

In 2007, BEA Systems was acquired for a total of 8.5 billion US dollars.

In 2009, a total of 7.4 billion US dollars to acquire SUN. In 2008, SUN acquired MySQL for US$1 billion. It means that Oracle has the management right of MySQL at the same time, and Oracle has become an absolute leader in the database field so far.

In 2013, Oracle surpassed IBM to become the second largest software company in the world after Microsoft. Today, Oracle's annual revenue of $40 billion is enough to justify the value of commercial (fee) database software.

SQL Server

SQL Server is a large-scale commercial database developed by Microsoft, which was born in 1989. C#, .net and other languages ​​are often used, fully integrated with WinNT, and can also be well integrated with Microsoft BackOffice products.

DB2

IBM's database products are charged. Often used in banking systems.

PostgreSQL

PostgreSQL is extremely stable, most in line with SQL standards, open source, and has commercial-grade DBMS quality. PG processes text and SQL with a large amount of data faster. 

SQLite

Embedded small database, applied on the mobile phone. Zero configuration, SQlite3 does not need to install, configure, start, shut down or configure database instances. When the system crashes, there is no need to do any recovery operations, and it will automatically recover when the database is used next time.

informix

Produced by IBM, derived from the combination of Information and Unix, it is the first commercial database product to be ported to Linux. Only run on unix/linux platform, command line operation. It has high performance, supports clusters, and is suitable for systems with extremely high security requirements, especially for banking and securities systems.

3. MySQL introduction

 

3.1 Overview

  • MySQL is an open source relational database management system, developed by Swedish MySQL AB (founder Michael Widenius) in 1995, and quickly became the No.1 open source database.
  • In 2008, it was acquired by Sun (1 billion US dollars), and in 2009, Sun was acquired by Oracle. MariaDB came into being. (The creator of MySQL worried about the risk of MySQL being closed source, so he created a MySQL branch project MariaDB)
  • After MySQL6.x version, it is divided into community edition and commercial edition.
  • MySQL is a relational database management system that keeps data in different tables instead of putting all the data in one big warehouse, which increases speed and improves flexibility.
  • MySQL is open source, so you don't need to pay extra.
  • MySQL can be customized, using the GPL (GNU General Public License) agreement, you can modify the source code to develop your own MySQL system.
  • MySQL supports large databases. Can handle large databases with tens of millions of records.
  • MySQL supports large databases and data warehouses with 50 million records. The 32-bit system table file can support a maximum of 4GB, and the 64-bit system supports a maximum table file of 8TB.
  • MySQL uses standard SQL data language forms.
  • MySQL can be allowed to run on multiple systems and supports multiple languages. These programming languages ​​include C, C++, Python, Java, Perl, PHP, and Ruby, among others. 

3.2 About MySQL8.0

MySQL released version 8.0 directly from version 5.7 , which shows that this is an exciting milestone version. The MySQL 8 version has made significant improvements and enhancements in terms of functions. The developers have refactored the source code of MySQL. The most prominent point is that the multiple MySQL Optimizers have been improved. Not only has the speed been improved, but it has also brought users better performance and a better experience.

Why do so many manufacturers choose MySQL? The main reasons can be summarized as follows:

  1. Open source code , low cost of use.
  2. Excellent performance and stable service.
  3. The software is small in size , easy to use, and easy to maintain.
  4. With a long history, users in the community are very active , and you can ask for help when you encounter problems.
  5. Many Internet companies are using it, and it has been verified by time.

3.3 Oracle vs MySQL

Oracle is more suitable for large multinational enterprises because they are not sensitive to costs, but have higher requirements for performance and security.

Due to its small size, fast speed, low overall cost of ownership, and the ability to handle large databases with tens of millions of records, especially the open source feature, many Internet companies and small and medium-sized websites choose MySQL as their website database (Facebook, Twitter, YouTube, Alibaba/Ant Financial, Qunar, Meituan Waimai, Tencent).

4. RDBMS and non-RDBMS

RDBMS: relational database

Non-RDBMS: Non-relational database

We can see from the rankings that relational databases are definitely the mainstream of DBMSs, and the most used DBMSs are Oracle, MySQL and SQL Server. These are relational databases (RDBMS) .

4.1 Relational database (RDBMS)

4.1.1 Substance

  • This type of database is the oldest type of database. The relational database model boils down complex data structures into simple binary relationships (that is, two-dimensional tables).
  • A relational database stores data in the form of rows and columns for easy understanding by users. This series of rows and columns is called a table , and a set of tables makes up a database
  • There is a relationship between tables and data records between tables . Various entities in the real world and various links between entities are represented by relational models . A relational database is a database based on a relational model.
  • SQL is the query language for relational databases.

 

4.1.2 Advantages

  • Complex query SQL statements can be
  • Transaction support enables the realization of data access requirements with high security performance.

4.2 Non-relational databases (non-RDBMS)

4.2.1 Introduction

A non-relational database can be regarded as a castrated version of a traditional relational database , which stores data based on key-value pairs and does not need to be parsed by the SQL layer, so its performance is very high . At the same time, performance is further improved by reducing less frequently used functions. At present, most of the mainstream non-relational databases are basically free.

4.2.2 What are the non-relational databases

Compared with SQL, NoSQL generally refers to non-relational databases, including key-value databases, document databases, search engines, and column stores on the list, as well as graph databases. Only by using the term NoSQL can these technologies be included.

key-value database

Key-value databases store data in the form of Key-Value keys , where Key and Value can be simple objects or complex objects. As a unique identifier, Key has the advantage of fast search speed, which is obviously better than relational databases in this respect. The disadvantage is that it cannot use conditional filtering (such as WHERE) like relational databases. If you don't know where to find data, you need to Iterating over all keys consumes a lot of computation.

A typical usage scenario for a key-value database is as an in-memory cache . Redis is the most popular key-value database.

document database

This type of database can store and retrieve documents, which can be in formats such as XML and JSON. In a database, a document is the basic unit for processing information, and a document is equivalent to a record. The documents stored in the document database are equivalent to the "values" stored in the key-value database. MongoDB is the most popular document database. In addition, there are CouchDB and so on.

search engine database

Although relational databases use indexes to improve retrieval efficiency, the efficiency of full-text indexes is low. Search engine database is a form of data storage used in the field of search engines. Since search engines will crawl a large amount of data and store them in a specific format, the optimal performance can be guaranteed during retrieval. The core principle is "inverted index". Typical products: Solr, Elasticsearch, Splunk, etc.

columnar database

Columnar databases are relative to row-based databases. Oracle, MySQL, SQL Server and other databases all use row-based storage (Row-based), while columnar databases store data in the database according to columns. The advantage is that it can greatly reduce the I/O of the system and is suitable for distributed file systems. The disadvantage is that the functions are relatively limited. Typical products: HBase, etc.

4.3 Summary

There are many classifications of NoSQL. Even so, in the DBMS ranking, the SQL camp still has a larger proportion. 4 of the top 5 DBMSs are relational databases, and 12 of the top 20 DBMSs are relational databases. . Therefore, mastering SQL is very necessary.

5 Relational Database Design Rules

  • The typical data structure of a relational database is a data table , and the composition of these data tables is structured (Structured)
  • Put the data into the table, and then put the table into the library
  • There can be multiple tables in a database, and each table has a name to identify itself. Table names are unique
  • Tables have some characteristics that define how data is stored in the table, similar to the design of "classes" in java and python

5.1 Tables, records, fields

  • There are three main concepts in the ER (entity-relationship, entity-relationship) model: entity set, attribute, and relationship set .
  • An entity set (class) corresponds to a table (table) in the database, and an entity (instance) corresponds to a row (row) in the database table, also known as a record (record). An attribute (attribute) corresponds to a column (column) in the database table, also known as a field (field).

5.2 Relationship between tables

  • There is a relationship between tables and data records between tables. Various entities in the real world and various links between entities are represented by relational models.
  • Four: one-to-one association, one-to-many association, many-to-many association, self-reference 

5.2.1 One-to-one association

There are not many applications in actual development, because one-to-one can be created as a table.

Example:

Design student table: student number, name, mobile phone number, class, department, ID number, home address, place of origin, emergency contact,...

Split into two tables: the records of the two tables have a one-to-one correspondence.

  • Basic information table (commonly used information): student number, name, mobile phone number, class, department
  • File information form (uncommonly used information): student number, ID number, home address, place of origin, emergency contact,...

Two table building principles:

  • Unique foreign key: The primary key of the main table and the foreign key (unique) of the secondary table form a primary-foreign key relationship, and the foreign key is unique.
  • The foreign key is the primary key: the primary key of the primary table and the primary key of the secondary table form a primary-foreign key relationship.

5.2.2 One-to-many relationship

Common example scenarios: customer table and order table, category table and commodity table, department table and employee table.

Example:

Employee table: number, name, ..., department

Department table: number, name, introduction

The principle of one-to-many table creation: create a field in the slave table (multi-party), and the field serves as a foreign key pointing to the primary key of the main table (one party) 

5.2.3 Many-to-many

To represent a many-to-many relationship, a third table must be created, often called a join table , which divides the many-to-many relationship into two one-to-many relationships . Insert the primary keys of both tables into the third table

5.3.4 Self reference 

 

Guess you like

Origin blog.csdn.net/m0_52096593/article/details/130874102