mysql advanced storage engine

1. mysql architecture

MySQL architecture refers to the internal composition and operating mechanism of the MySQL database system. It includes three main layers: application layer, service layer and storage engine layer.

The application layer is the top layer of the MySQL architecture. It provides an interface for applications to access MySQL services, mainly including the following:

  • Connection handling: Responsible for establishing, maintaining and disconnecting connections between clients and servers.
  • User authentication: Responsible for verifying the client's identity and permissions, and encrypting communications.
  • Security management: Responsible for preventing attacks such as SQL injection, as well as backing up and restoring data.

The service layer is the core layer of the MySQL architecture. It completes most of the core service functions, mainly including the following:

  • SQL interface: Responsible for receiving SQL commands from the client and returning execution results.
  • Query parser: Responsible for syntax analysis and semantic checking of SQL commands and generating parse trees.
  • Query optimizer: Responsible for optimizing the parse tree and selecting the best execution plan.
  • Query cache: Responsible for caching commonly used query results to improve query efficiency.
  • Storage engine API: Responsible for communicating with different storage engines and shielding underlying differences.

The storage engine layer is the lowest layer of the MySQL architecture. It is responsible for data storage and reading, and mainly includes the following contents:

  • Storage engine: Responsible for implementing different data storage methods, such as InnoDB, MyISAM, Memory, etc.
  • Data files: Responsible for storing data in the file system, such as .frm, .ibd, .myd, .myi, etc.

2. Storage engine overview

 The storage engine is the implementation of technologies such as storing data, creating indexes, and updating/querying data. The storage engine is table-based, not library-based, so the storage engine can also be called a table type.

2.1 Query table creation statement

 2.2 Specify storage engine

When creating a table in MySQL, you can specify the storage engine through ENGINE. Just add engine=storage engine; at the end of the create statement.

create table user (
    id int not null,
    name varchar(30) default null,
    pwd varchar(30) default null,
    primary key(id)
) engine=InnoDB;

MySQL supports a variety of different storage engines, each of which has its own characteristics and applicable scenarios. Some common storage engines are:

  • InnoDB: A storage engine that supports transactions, row-level locks, foreign key constraints, and automatic recovery, suitable for processing update-intensive and transactional tables.
  • MyISAM: A storage engine that does not support transactions, table-level locks, full-text indexes, and compression, and is suitable for processing select-intensive and insert-intensive tables.
  • Memory: A storage engine that stores data in memory, providing high performance, but the data is not persistent and is suitable for processing temporary and small tables.
  • CSV: A storage engine that stores data in CSV format files to facilitate data import and export, but does not support indexing and partitioning. It is suitable for processing simple and portable tables.
  • Archive: A storage engine for archiving data. It only supports insertion and query operations, but does not support indexing and update operations. It is suitable for processing a large number of tables that do not change frequently.

2.3 Query support engine

3. Storage engine InnoDB

Introduction
InnoDB is a general-purpose storage engine that combines high reliability and high performance. After MySQL 5.5, InnoDB is the default MySQL storage engine.
Features

  • DML operations follow the ACID model and support transactions;
  • Row-level locks to improve concurrent access performance;
  • Supports foreign key FOREIGN KEY constraints to ensure data integrity and correctness;

File
xxx.ibd: xxx represents the table name. Each table in the innoDB engine will correspond to such a table space file, which stores the table structure (frm, sdi), data and indexes of the table.
Parameter: innodb_file_per_table

 4. MyISAM

Introduction
MyISAM is the early default storage engine of MySQL.
Features

  • Does not support transactions, does not support foreign keys
  • Supports table locks, but does not support row locks
  • Fast access

File
xxx.sdi: store table structure information
xxx.MYD: store data
xxx.MYI: store index

5. Storage engine Memory

The table data introduced
in the Memory engine are stored in memory. Due to hardware problems or power outages, these tables can only be used as temporary tables or caches .
Features

  • memory storage
  • hash index (default)

File
xxx.sdi: stores table structure information
 

6. Engine Features and Selection

6.1 Features

6.2 Choice

Guess you like

Origin blog.csdn.net/qq_62377885/article/details/132981822