MySQL札记13_数据库引擎Engine

作者: 皮皮大 | 来源:发表于2019-08-04 20:43 被阅读3次

    在MySQL数据库中常用的引擎有两种:MyISAMInnoDB。其他的还有BLOCKHOLE、CSV、MEMORY、Archive

    MySQL数据库引擎
    mysql数据库引擎常用面试总结
    MySQL的InnoDB原理详解
    B+Tree index structures in InnoDB

    什么是存储引擎

    MySQL中的数据用各种不同的技术存储在文件(或者内存)中。这些技术中的每一种技术都使用不同的·存储机制、索引技巧、锁定水平·并且最终提供广泛的\、不同的功能和能力。通过选择不同的技术,你能够获得额外的速度或者功能,从而改善你的应用的整体功能。

    • 不同的存储方式使用不同的存储技巧
    • 不同的存储方式带来不同的性能体验

    常用的存储引擎

    存储引擎主要有:

    • MyIsam
    • InnoDB
    • Mrg_Myisam
    • Memory
    • Blackhole
    • CSV
    • Performance_Schema
    • Archive
    • Federated

    怎么查看MySQL数据库引擎

    mysql>  show engines;
    
    image.png

    或者带上参数G

    mysql>  show engines\G;
    
    *************************** 1. row ***************************
          Engine: InnoDB
         Support: DEFAULT
         Comment: Supports transactions, row-level locking, and foreign keys
    Transactions: YES
              XA: YES
      Savepoints: YES
    *************************** 2. row ***************************
          Engine: MRG_MYISAM
         Support: YES
         Comment: Collection of identical MyISAM tables
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 3. row ***************************
          Engine: MEMORY
         Support: YES
         Comment: Hash based, stored in memory, useful for temporary tables
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 4. row ***************************
          Engine: BLACKHOLE
         Support: YES
         Comment: /dev/null storage engine (anything you write to it disappears)
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 5. row ***************************
          Engine: MyISAM
         Support: YES
         Comment: MyISAM storage engine
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 6. row ***************************
          Engine: CSV
         Support: YES
         Comment: CSV storage engine
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 7. row ***************************
          Engine: ARCHIVE
         Support: YES
         Comment: Archive storage engine
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 8. row ***************************
          Engine: PERFORMANCE_SCHEMA
         Support: YES
         Comment: Performance Schema
    Transactions: NO
              XA: NO
      Savepoints: NO
    *************************** 9. row ***************************
          Engine: FEDERATED
         Support: NO
         Comment: Federated MySQL storage engine
    Transactions: NULL
              XA: NULL
      Savepoints: NULL
    9 rows in set (0.00 sec)
    
    ERROR: 
    No query specified
    
    • 查看创建表时的引擎
      MySQL5.6之后默认的引擎是InnoDBshow create table student;

      image.png
    • 创建表时直接指定引擎

    mysql> create table test (name varchar(20)) ENGINE=MyIsam;
    Query OK, 0 rows affected (0.01 sec)
    
    # 查看索引
    mysql> show create table test;
    +-------+----------------------------------------------------------------------------------------------+
    | Table | Create Table                                                                                 |
    +-------+----------------------------------------------------------------------------------------------+
    | test  | CREATE TABLE `test` (
      `name` varchar(20) DEFAULT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
    +-------+----------------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)
    
    • 如果不指定,默认是InnoDB
      image.png

    MyIsam 和InnoDB对比

    MyIsam InnoDB
    支持全文索引 支持全文索引(5.6以后开始支持,之前的版本不支持)
    不支持事务 支持事务
    表级锁 行级锁,外键约束
    性能较差 性能较好(比较而言)
    主要功能是查和增加,效率 主要增强事务,效率
    崩溃恢复差 崩溃恢复好,通过bin-log日志

    相关文章

      网友评论

        本文标题:MySQL札记13_数据库引擎Engine

        本文链接:https://www.haomeiwen.com/subject/jfzydctx.html