Database MySQL - storage engine

Table of contents

1. MySQL architecture

2. Introduction to storage engine

3. Storage Engine Features

1. InnoDB

2. MyISAM

3. Memory

4. Storage engine selection


1. MySQL architecture

  •  Connection layer: The top layer is some clients and connection services, which mainly complete some connection processing, authorization and authentication, and related security solutions. The server also verifies the operating authority it has for each client that accesses securely.

  • 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 execution of some built-in functions. All cross-storage engine functions are also implemented at this layer, such as procedures and functions.

  • Engine 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 execution of some built-in functions. All cross-storage engine functions are also implemented at this layer, such as procedures and functions.

  • Storage layer: It mainly stores data on the file system and completes the interaction with the storage engine.

2. Introduction to storage engine

The storage engine is the implementation of technologies such as storing data, building indexes, and updating/querying data. The storage engine is based on tables , not libraries, so storage engines can also be called table types. 

-- 查询建表语句
show create table account;

① When creating a table, specify the storage engine:

             CREATE TABLE table name (
                            field 1 field 1 type [ COMMENT field 1 comment ],
                             .....
                            field n field n type [ COMMENT field n comment ]

              ) ENGINE = INNODB [ COMMENT table comment ];

② View the storage engines supported by the current database: SHOW ENGINES ;

-- 查询当前数据库支持的存储引擎
show engines ;

 Example of how to create a table definition storage engine:

-- 创建表my_myisam,并指定MYISAN存储引擎
create  table my_myisam(
    id int ,
    name varchar(10)
)engine  = MYISAN;
-- 创建表my_memory,指定Memory存储引擎\
create  table my_memory(
    id int ,
    name varchar(10)
)engine  = Memory;

3. Storage Engine Features

features innoDB MyISAM Memory
storage limit 64TB have have
transaction security support - -
lock mechanism row lock table lock table lock
B+tree index support support support
Hash index - - -
full text index Supported (after version 5.6) support -
space use high Low N/A
memory usage high Low medium
Bulk Insertion Speed Low high medium
Support for foreign keys support - -

1. InnoDB

① Introduction: InnoDB is a general-purpose storage engine that takes into account high reliability and high performance. After My5QL 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;
  • Support 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. Parameters: innodb_file_per_table

View system variables, you can:

-- 模糊匹配
show variables like 'innodb_file_per_table';

It is enabled by default, indicating that each table will correspond to such a tablespace file.

2. MyISAM

① Introduction: MylSAM is the early default storage engine of MySQL.

② Features:

  • Does not support transactions, does not support foreign keys
  • Table locks are supported, but row locks are not supported
  • fast access

③ Documents:

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

3. Memory

① Introduction: The table data of the Memory engine is stored in the memory. Due to hardware problems or power failure problems, these tables can only be used as temporary tables or caches.

② Features:

  • memory storage
  • hash index (default)

③ File: xxx.sdi: store table structure information

4. Storage engine selection

When choosing a storage engine, you should choose a suitable storage engine according to the characteristics of the application system. For complex application systems, you can also choose a combination of multiple storage engines according to the actual situation.

  • InnoDB: It is the default storage engine of Mysql, which supports transactions and foreign keys. If the application has relatively high requirements for the integrity of the transaction, requires data consistency under concurrent conditions, and data operations include many update and delete operations in addition to insert and query, then the InnoDB storage engine is a more suitable choice .

  • MyISAM: If the application is mainly read and insert operations, with few update and delete operations, and the requirements for transaction integrity and concurrency are not very high, then this storage engine is very suitable to choose.

  • MEMORY: Store all data in memory, with fast access speed, usually used for temporary tables and caches. The disadvantage of MEMORY is that there is a limit on the size of the table. Too large a table cannot be cached in memory, and data security cannot be guaranteed.
     

Guess you like

Origin blog.csdn.net/hdakj22/article/details/129765773