当前位置:网站首页>Mysql23 storage engine

Mysql23 storage engine

2022-07-06 10:33:00 Protect our party a Yao

One . View storage engine

  • see mysql What storage engine is provided :
show engines;

 Insert picture description here

show engines \G;

 Insert picture description here
 Insert picture description here

Two . Set the default storage engine of the system

  • View the default storage engine :
show variables like '%storage_engine%';
# or 
SELECT @@default_storage_engine;

 Insert picture description here  Insert picture description here

  • Modify the default storage engine
    If the storage engine of the table is not explicitly specified in the statement creating the table , That will default to InnoDB As a storage engine for tables . If we want to change the default storage engine of the table , You can write the command line to start the server like this .
SET DEFAULT_STORAGE_ENGINE=MyISAM;

Or modify my.cnf file :

default-storage-engine=MyISAM
#  Restart the service 
systemctl restart mysqld.service

3、 ... and . Set the storage engine for the table

The storage engine is responsible for extracting and writing the data in the table , We can Different tables set different storage engines , In other words, different tables can have different physical storage structures , Different extraction and writing methods .

3.1. Specify the storage engine when creating the table

Our previous statements to create tables did not specify the storage engine of the table , Then the default storage engine will be used InnoDB . If we want to explicitly specify the storage engine of the table , It can be written like this :

CREATE TABLE  Table name (
 Create table statement ;
) ENGINE =  Storage engine name ;

3.2. Modify the storage engine of the table

If the table has been built , We can also use the following statement to modify the storage engine of the table :

ALTER TABLE  Table name  ENGINE =  Storage engine name ;
create table engine_demo_table(
     c1 int primary key,
     c2 varchar(25));
     
show create table engine_demo_table; 
alter table engin_demo_table engine=MYISAM;
show create table engine_demo_table; 

 Insert picture description here

Four . Engine introduction

4.1. InnoDB engine : Transaction storage engine with foreign key support

  1. MySQL from 3.23.34a Start with InnoDB Storage engine . Greater than or equal to 5.5 after , By default InnoDB engine .
  2. InnoDB yes MySQL Of Default transactional engine , It's designed to handle a lot of short-term (short-lived) Business . It can ensure the complete submission of transactions (Commit) And rollback (Rollback).
  3. In addition to adding and querying , It needs to be updated 、 Delete operation , that , Preference should be given to InnoDB Storage engine .
  4. Unless there's a very special reason to use another storage engine , Otherwise, priority should be given to InnoDB engine .
  5. Data file structure :
  • Table name .frm Storage table structure (MySQL8.0 when , Merge in table name .ibd in ).
  • Table name .ibd Store data and index .
  1. InnoDB yes Designed for maximum performance in handling huge amounts of data .
  • In previous releases , Dictionary data is stored as metadata files 、 Non transaction table, etc . Now these metadata files have been deleted . such as : .frm , .par , .trn , .isl , .db.opt Waiting MySQL8.0 There is no such thing as .
  1. contrast MyISAM Storage engine for , InnoDB The processing efficiency of writing is poor , And it will take up more disk space to save data and indexes .
  2. MyISAM Cache index only , Don't cache real data ;InnoDB Not only index but also real data , High memory requirements , And memory size has a decisive impact on performance .

4.2. MyISAM engine : The main non transactional storage engine

  1. MyISAM There are a lot of features , Include full text index 、 Compress 、 Space function (GIS) etc. , but MyISAM Unsupported transaction 、 Row-level locks 、 Foreign keys , There is no doubt that the defect is Can't recover safely after a crash .
  2. 5.5 The previous default storage engine .
  3. The advantage is access Fast , There is no requirement for transaction integrity or SELECT、INSERT Mainly applications .
  4. There is additional constant storage for data statistics . so count(*) The query efficiency is very high .
  5. Data file structure :
  • Table name .frm Storage table structure .
  • Table name .MYD Store the data (MYData).
  • Table name .MYI Storage index (MYIndex).
  1. Application scenarios : Read only applications or read-only businesses .

4.3. Archive engine : For data archiving

  • The following table shows ARCHIVE Storage engine functions
features Support
B Tree index I won't support it
Backup / Time to recover ( Implement... In the server , Not in the storage engine ) Support
Cluster database supports I won't support it
Clustered index I won't support it
compressed data Support
Data caching I won't support it
Encrypt data ( The encryption function is implemented in the server ) Support
Foreign key support I won't support it
Full text search index I won't support it
Geospatial data types support Support
Geospatial index support I won't support it
Hash index I won't support it
The index buffer I won't support it
Lock granularity Row lock
MVCC I won't support it
Storage limits No restrictions
transaction I won't support it
Update the statistics of the data dictionary Support

4.4. Blackhole engine : Discard write operation , The read operation will return empty content

4.5. CSV engine : When storing data , Separate data items with commas

Use cases are as follows

create table testcsv (
    i int not null,
    c char(10) not null) engine=CSV;
INSERT INTO testcsv VALUES(1,'record one'),(2,'record two');
select * from testcsv;

 Insert picture description here

cd /var/lib/mysql
cd MYSQLTEST/

 Insert picture description here

4.6. Memory engine : Table in memory

summary :
Memory The logical medium used is Memory , Fast response , But when mysqld When the daemon crashes Data will be lost . in addition , The stored data is required to be in a format with constant data length , such as ,Blob and Text Data of type is not available ( Of variable length ).
Main features :

  1. Memory meanwhile Support hash (HASH) Indexes and B+ Tree index .
  2. Memory The watch is at least better than MyISAM Table One order of magnitude fast .
  3. MEMORY The size of the table is limited Of . The size of the table mainly depends on two parameters , Namely max_rows and max_heap_table_size . among ,max_rows You can specify... When creating a table ;max_heap_table_size The default size of is 16MB, It can be expanded as needed .
  4. Data files are stored separately from index files .
  5. shortcoming : Its data is easy to lose , Short life cycle . Based on this flaw , choice MEMORY You need to be very careful when storing the engine .
    Use Memory Storage engine scenario :
  6. The target data is relatively small , And very Frequent visits , Store data in memory , If the data is too large, it will cause out of memory . You can use the parameter max_heap_table_size control Memory The size of the table , Limit Memory The maximum size of the table .
  7. If The data is provisional , and Must be available immediately obtain , Then you can put it in memory .
  8. Stored in Memory If the data in the table suddenly If you lose it, it doesn't matter much .

4.7. Federated engine : Access remote tables

Federated The engine is accessing other MySQL One of the servers agent , Although the engine seems to provide a good Cross server flexibility , But it often brings problems , therefore It is disabled by default .

4.8. Merge engine : Manage multiple MyISAM A collection of tables made up of tables

4.9.NDB engine :MySQL Cluster specific storage engine

It's also called NDB Cluster Storage engine , It is mainly used for MySQL Cluster Distributed cluster Environmental Science , Be similar to Oracle Of RAC colony .

4.10. Engine comparison

MySQL In the same database , Different storage engines can be selected for different tables . The following table compares the common storage engines .

原网站

版权声明
本文为[Protect our party a Yao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060911326073.html