MySQL (advanced—, storage engine)

MySQL (advanced—, storage engine)

(Advanced 7 parts: storage engine, index [core], SQL optimization, views/stored procedures/triggers, locks, innoDB engine, MySQL management)

  1. Mysql architecture

    Insert image description here

    1. Connection layer: handles client connections, handles authentication, and request operations
    2. Service layer: SQL interface, SQL parsing, SQL optimization (all cross-storage engine operations are processed in the service layer)
    3. Engine layer (pluggable, index implementation layer)
    4. Storage layer (storage related data, data indexes, files and logs)
  2. Introduction to storage engines

  3. Storage engine features

    A universal storage engine that takes into account high reliability and high performance. After mysql5.5, innoDB is the default storage engine of mysql.

    -- 查看当前数据库支持的数据引擎
    SHOW ENGINES;
    -- 创建表的时候指定存储引擎
    create table xxx(......) engine = iniodb;
    
    1. Features of innoDB:

      • DML (data addition, deletion and modification) operations follow the ACID (atomicity, isolation, consistency, durability) model and supporttransactions
      • Row-level lock, improve concurrent access performance
      • SupportsForeign KeyFOREIGN KEY constraints to ensure data integrity and correctness
    2. document

      • xxx.ibd (each table in the innoDB engine corresponds to this table space file) stores the table structure (frm, sdi), data and indexes of the table.

      • Parameters: innodb_file_per_table (open by default in mysql8.0, identifying each table corresponding to a table space file)

      -- 查看表空间文件的开关
      show variables like 'innodb_file_table';
      
      • mysql data storage directory:C:\ProgramData\MySQL\MySQL Server 8.0\Data stores the table structure of the current database, the data stored in the current database, and indexes. This file is binary and cannot be viewed directly查看方式:ibd2sdi account.ibd
    3. innoDB logical storage structure

      • TableSpece: table space, such as ibd file, contains several segments
      • Segment: Segment, contains several Extents
      • Extent: area, contains several pages, the area size is fixed (1M can contain 16 pages)
      • Page: Page, including several Rows (the smallest unit of disk operations). The page size is fixed (16K)
      • Row: row, including trxId, roll point, col1, col2,…

    MyISAM is the early default storage engine of mysql.

    1. Features of MyISAM
      • Does not support transactions, does not support foreign keys
      • Supports table locks, but does not support row locks
      • Fast access
    2. document
      • .MYD data
      • .MYI index
      • .sdi table structure (text file json format)

    Memory storage engine stores data in memory. Due to hardware or power outages, these tables can only be used as temporary tables or caches.

    1. Features of Memory:

      • memory storage
      • hash index (default)
    2. document

      .sdi storage table structure (because the data is stored in memory)

    3. The differences between the three storage engines:

    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 - - support
    Full Text Search Supported (after version 5.6) support -
    space usage high low N/A
    memory usage high low medium
    Batch insert speed low high high
    Support foreign keys support - -
  4. Storage engine application

    Choose an appropriate storage engine based on the characteristics of the application system. For complex systems, multiple storage engines can be selected and combined according to actual conditions.

    • innoDB: supports transactions, foreign keys, and row locks. There are requirements for transaction integrity and concurrency scenario consistency.
    • MyISAM: Mainly data read operations and insert operations, with only a few update and delete operations, and the integrity of the transaction and the concurrency are not very high, then this storage engine is suitable. Such as log operations, e-commerce footprints and comments (non-core data). (MongoDB)
    • Memory: Saved in memory, access speed is fast, long-term use as temporary table and cache. The disadvantage is that the size of the table is limited. Tables that are too large cannot be cached in memory, and data security cannot be guaranteed. (Redis)

Guess you like

Origin blog.csdn.net/weixin_52154534/article/details/134992233