32 存储引擎?

32 存储引擎?
    
    完整的建表语句
    create table `t_x`(
        `id` int(11) default null
    ) enging=innodb default charset=utf-8;
    
    注意:在mysql当中,凡是标识符是可以使用飘号括起来的。最好别用,不通用。
        
    建表的时候可以指定存储引擎,也可以指定字符集。
    
    mysql默认使用的存储引擎是InnoDB的方式
    默认采用的字符集是utf-8
    
    什么是存储引擎呢?
        存储引擎这个名字只有在mysql中存在。(Orcale中有对应的机制,但是不叫做存储引擎。Orcale中没有特殊的名字,就是“表的存储方式”)
        
        mysql支持很多存储引擎,每一个存储引擎都对应了一种不同的存储方式。
        每一个存储引擎都有自己的优缺点,需要在合适的时机选择合适的存储引擎。
        
    查看当前mysql支持的存储引擎?
        show engiines \G;
        *************************** 1. row ***************************
             Engine: FEDERATED
            Support: NO
            Comment: Federated MySQL storage engine
        Transactions: NULL
                  XA: NULL
          Savepoints: NULL
        *************************** 2. row ***************************
              Engine: MRG_MYISAM
             Support: YES
             Comment: Collection of identical MyISAM tables
        Transactions: NO
                  XA: NO
          Savepoints: NO
        *************************** 3. row ***************************
              Engine: MyISAM
             Support: YES
             Comment: MyISAM storage engine
        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: CSV
             Support: YES
             Comment: CSV storage engine
        Transactions: NO
                  XA: NO
          Savepoints: NO
        *************************** 6. row ***************************
              Engine: MEMORY
             Support: YES
             Comment: Hash based, stored in memory, useful for temporary tables
        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: InnoDB
             Support: DEFAULT
             Comment: Supports transactions, row-level locking, and foreign keys
        Transactions: YES
                  XA: YES
          Savepoints: YES
        *************************** 9. row ***************************
              Engine: PERFORMANCE_SCHEMA
             Support: YES
             Comment: Performance Schema
        Transactions: NO
                  XA: NO
          Savepoints: NO
        
    常见的存储引擎?
    
        Engine: MyISAM
             Support: YES
             Comment: MyISAM storage engine
        Transactions: NO
                  XA: NO
          Savepoints: NO
          
         MyISAM这种存储引擎不支持事务。
         My ISAM是mysql最常用的存储引擎,但是这种引擎不是默认的。
         MyISAM采用三个文件组织一张表:
            xxx.frm(存储格式的文件)
            xxx.MYD(存储表中数据的文件)
            xxx.MYI(存储表中索引的文件)
        优点:可被压缩,节省存储空间。并且可以转换为只读表,提高检索效率。
        缺点:不支持事务。
        
        -----------------------------------------------------------------------------
        
        Engine: InnoDB
             Support: DEFAULT
             Comment: Supports transactions, row-level locking, and foreign keys
        Transactions: YES
                  XA: YES
          Savepoints: YES
          
        优点:支持事务、行级锁、外键等。这种存储引擎数据的安全全得到保障。
        
        表的结构存储在xxx.frm文件中
        数据存储在tablespace这样的表空间中(逻辑概念),无法被压缩,无法转换成只读。
        这种InnoDB存储引擎在mysql数据库崩溃之后提供自动恢复机制。
        InnoDB支持级联删除和级联更新。
        
        -----------------------------------------------------------------------------
        
        Engine: MEMORY
             Support: YES
             Comment: Hash based, stored in memory, useful for temporary tables
        Transactions: NO
                  XA: NO
          Savepoints: NO
          
         缺点:不支持事务,数据容易丢失。因为所有数据和索引都是存储在内存当中的。
         优点:查询速度最快。
         以前叫做HEAP引擎。
posted @ 2020-09-09 16:51  xlwu丶lz  阅读(148)  评论(0编辑  收藏  举报