当前位置:网站首页>Alignment HR_ MySQL storage engine, so it is

Alignment HR_ MySQL storage engine, so it is

2022-06-10 08:53:00 Javanese aborigines, joelib

MySQL Advanced storage engine

Thank you very much " a brand of instant noodles "

1. first impressions are strongest

1.1 see MySQL Supported storage engines

SHOW ENGINES;

 Insert picture description here

1.2 View of the default storage engine

# Method 1 
SHOW VARIABLES LIKE '%storage_engine%'

# Method 2 
SELECT @@SESSION.default_storage_engine;

1.3 Modify the default storage engine

# Method 1   Modify the system variable of the current session layer 
SET SESSION default_storage_engine = ' Storage engine ';

# Method 2   modify my.cnf The configuration file 
[mysqld]
default_storage_engine =  Storage engine ;

1.4 Specify the corresponding storage engine when creating the table

CREATE TABLE IF NOT EXISTS table_name (
	field_name data_type constraint,
    field_name data_type constraint,
    field_name data_type constraint
)engine = ' Storage engine ';

# If no storage engine is specified, the default storage engine is used Innodb

1.5 Modify the storage engine of the table

ALTER TABLE table_name engine = ' Storage engine ';

2. The introduction of storage engine

2.1 What is a storage engine

  • The storage engine can be understood as a table type , That is, it seems that variables have corresponding data types , Tables also have corresponding types , It's the storage engine
  • The storage engine determines how the table handles the data
  • Be careful : The above two points are based on the fact that the storage engine determines the underlying index , Indexes correspond to different data structures

2.2Innodb Storage engine

  • since MySQL5.5 after , The default storage engine is changed to Innodb, The previous default storage engines were MYISAM

    • No special circumstances , priority of use Innodb
  • Innodb It's transactional , namely Innodb Support Rollback operation \

  • Innodb It supports foreign key constraints

  • common DML operation Such as SELECT UPDATE DELETE INSERT Should be used Innodb This storage engine

    • The main reasons for using this engine are MySQL Yes Innodb Optimized , More efficient
    • Underlying index MYISAM The corresponding non clustered index is theoretically more efficient Later on
  • File directory

    • MySQL8.0
      • .ibd Table structure + Table data / Indexes ( Data is index , Index and data )
    • MySQL5.7
      • .opt database information
      • .frm: Table structure
      • .ibd: Table data / Indexes ( Data is index , Index is data )

2.3MYISAM Storage engine

  • MYISAM Neither foreign key constraints nor transactions are supported
  • MYISAM The biggest advantage is high query efficiency , It is also related to non clustered indexes
  • File directory
    • MYSQL8.0
      • .MYD Store the data
      • .MYI Storage index
      • .sdi Table structure
    • MySQL5.7
      • .MYD Store the data
      • .MYI Storage index
      • .frm Table structure
      • .opt database information

2.4Innodb and MYISAM The difference between

Contrast item MYISAMInnoDb explain
Foreign keys I won't support it Support
Business I won't support it Support
Row table lock Table lock Row-level locks With Java For example , Be similar to synchronized The role of
cache Cache index only , Don't cache data Data and indexes are cached together The reason is also related to whether the underlying is a clustered index , therefore ,InnoDb Higher cache requirements , To a certain extent i Choose which performance
Use the self-contained system table YN
concerns Save resources , Less consumption , Simple business High concurrency , Business , Large amount of data
Default installation YY
By default NY

2.5Archive Storage engine

  • Archive It's called archiving , As the name suggests, its main function is to Archive the data , Data archiving
  • because Archive The main function of is to archive , It supports DML operation Only SELECT & INSERT operation
    • among SELECT It's less efficient ,INSERT Very efficient

2.6Blackhole Storage engine

  • stay Blackhole In the storage engine ,INSERT Operation not allowed ,SELECT The operation returns NULL
  • therefore DML The core query and insert operations are invalid , This storage engine makes no sense

2.7CSV Storage engine

  • CSV The biggest highlight of the storage engine is that it generates the following file directories
    • .CSV This file stores the data in the table , This file can be opened by other software , Such as Excel etc.
    • .CSM This file stores the status of the table
  • CSV The most important function is to visualize the tables in the database , You can open it directly with other software , Be similar to JSON and XML

2.8Memory Storage engine

  • Memory The biggest highlight of the storage engine is , Other storage engines store data on disk , and Memory The data is stored in memory
    • so memory In the file directory structure under , stay mysq5.7 Only .frm file , stay mysql8.0 There are no documents
  • Because the data is stored in memory
    1. The response speed is very fast , Query efficiency is very high The bottom layer is the hash index , The time complexity of the query element is O(1), Even if it's B+Tree The corresponding cluster index is also O(log2N)
    2. Data is easy to lose , Short life cycle once mysql Service terminated , Or restart , The corresponding memory will disappear
  • Memory Data files and index files are stored separately , Because the bottom layer is not Cluster index
  • Memory The size of is limited , Mainly depends on max_rows and max_heap_table_size
    • max_rows When creating a table, you can specify
    • max_heap_table_size The default is 16mb, It can be increased as needed
    • The above two are similar to the relationship between independent variables and dependent variables
  • Memory Usage scenarios of
    • The data is provisional , And must be used immediately , And it doesn't matter if the data is discarded
    • The amount of data is relatively small , And be used frequently
      • In fact, this sentence is not accurate , For the bottom layer Hash index It is not suitable to do some Sort , Find range values The operation of

Similar to the relationship between independent variable and dependent variable

  • Memory Usage scenarios of
    • The data is provisional , And must be used immediately , And it doesn't matter if the data is discarded
    • The amount of data is relatively small , And be used frequently
      • In fact, this sentence is not accurate , For the bottom layer Hash index It is not suitable to do some Sort , Find range values The operation of
原网站

版权声明
本文为[Javanese aborigines, joelib]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206100842442987.html