Table of contents
Introduction to storage engines
Let’s start learning the first content of the advanced chapter - storage engine
Divided into four points to learn:
- MySQL architecture
- Introduction to storage engines
- Storage engine features
- Storage engine selection
MySQL architecture
connection layer
The top layer is some client and connection services, including local
sock
communication and most TCP/IP-like communication based on client
/
server tools. It mainly completes some
connection processing
,
authorization authentication
and related security solutions. The concept of thread pool is introduced on this layer to provide threads for clients that securely access through authentication. SSL-based secure links can also be implemented on this layer.
The server also verifies the operating permissions it has for each client that securely accesses it.
service layer
The second layer architecture mainly completes most of
the core service functions
, such as
SQL interface, and completes cached queries, SQL analysis and optimization, and the execution of some built-in functions
. All cross-storage engine functions are also implemented in this layer, such as procedures, functions, etc. At this layer, the server will parse the query and create the corresponding internal parse tree, and complete the corresponding optimization such as determining the order of table queries, whether to use indexes, etc., and finally generate the corresponding execution operations. If it is a select
statement, the server will also query the internal cache. If the cache space is large enough, this can greatly improve the performance of the system in an environment that solves a large number of read operations.
engine layer
Storage engine layer, the storage engine is really
responsible for the storage and retrieval of data in MySQL
, and the server
communicates with the storage engine through
the API .
Different storage engines have different functions, so we can
choose the appropriate storage engine according to our needs
.
Indexes in the database are implemented at the storage engine layer
.
storage layer
The data storage layer mainly stores data (such as: redolog, undolog, data, index, binary log, error log, query
logs, slow query logs, etc.) are stored on the file system and complete the interaction with the storage engine.
Compared with other databases,
MySQL
is a little different. Its architecture can be applied and work well in many different scenarios. Mainly reflected in the storage engine,
the plug-in storage engine architecture
separates query processing from other system tasks and data storage and extraction.
This architecture allows the selection of appropriate storage engines based on business needs and actual needs.
Introduction to storage engines
An engine is an engine, the core component of a machine.
For example, for carrier-based aircraft, helicopters, and rockets, they all have their own engines, which are their most core components. When we choose an engine, we need to choose the appropriate storage engine in the appropriate scenario, just like on a helicopter, we cannot choose the engine of a carrier-based aircraft.
The same goes for the storage engine. It is the core of the MySQL database. We also need to choose the appropriate storage engine in the appropriate scenario. Next, let’s introduce the storage engine
For example, for carrier-based aircraft, helicopters, and rockets, they all have their own engines, which are their most core components. When we choose an engine, we need to choose the appropriate storage engine in the appropriate scenario, just like on a helicopter, we cannot choose the engine of a carrier-based aircraft.
The same goes for the storage engine. It is the core of the MySQL database. We also need to choose the appropriate storage engine in the appropriate scenario. Next, let’s introduce the storage engine
concept
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. We can specify the selected storage engine when creating a table. If not specified, the default storage engine will be automatically selected.
statement
1. Specify the storage engine when creating the table
CREATE TABLE 表名(
字段1 字段1类型 [ COMMENT 字段1注释 ] ,
......
字段n 字段n类型 [COMMENT 字段n注释 ]
) ENGINE = INNODB [ COMMENT 表注释 ] ;
2. Query the storage engines supported by the current database
show engines;
3. Query table creation statement --- Default storage engine : InnoDB
show create table 表名;
When creating a table, even if we do not specify the storage epidemic, the database will automatically select the default storage engine.
Demo
1. Create the table
my_myisam
and specify the
MyISAM
storage engine
create table my_myisam(
id int,
name varchar(10)
) engine = MyISAM ;
2. Create the table my_memory and specify the Memory storage engine
create table my_memory(
id int,
name varchar(10)
) engine = Memory ;
END
Learn from: Dark Horse Programmer - MySQL Database Course