拆件式存储引擎是MySQL数据库最重要的特性之一。

    1. 查看当前MySQL支持的引擎类型。

      1. show engines \G
      2. *************************** 1. row ***************************
      3. Engine: InnoDB
      4. Support: DEFAULT
      5. Comment: Supports transactions, row-level locking, and foreign keys
      6. Transactions: YES
      7. XA: YES
      8. Savepoints: YES
      9. *************************** 2. row ***************************
      10. Engine: MRG_MYISAM
      11. Support: YES
      12. Comment: Collection of identical MyISAM tables
      13. Transactions: NO
      14. XA: NO
      15. Savepoints: NO
      16. *************************** 3. row ***************************
      17. Engine: MEMORY
      18. Support: YES
      19. Comment: Hash based, stored in memory, useful for temporary tables
      20. Transactions: NO
      21. XA: NO
      22. Savepoints: NO
      23. *************************** 4. row ***************************
      24. Engine: BLACKHOLE
      25. Support: YES
      26. Comment: /dev/null storage engine (anything you write to it disappears)
      27. Transactions: NO
      28. XA: NO
      29. Savepoints: NO
      30. *************************** 5. row ***************************
      31. Engine: MyISAM
      32. Support: YES
      33. Comment: MyISAM storage engine
      34. Transactions: NO
      35. XA: NO
      36. Savepoints: NO
      37. *************************** 6. row ***************************
      38. Engine: CSV
      39. Support: YES
      40. Comment: CSV storage engine
      41. Transactions: NO
      42. XA: NO
      43. Savepoints: NO
      44. *************************** 7. row ***************************
      45. Engine: ARCHIVE
      46. Support: YES
      47. Comment: Archive storage engine
      48. Transactions: NO
      49. XA: NO
      50. Savepoints: NO
      51. *************************** 8. row ***************************
      52. Engine: PERFORMANCE_SCHEMA
      53. Support: YES
      54. Comment: Performance Schema
      55. Transactions: NO
      56. XA: NO
      57. Savepoints: NO
      58. *************************** 9. row ***************************
      59. Engine: FEDERATED
      60. Support: NO
      61. Comment: Federated MySQL storage engine
      62. Transactions: NULL
      63. XA: NULL
      64. Savepoints: NULL
    2. 创建表示可以使用engine关键字指定引擎。```sql create table test4(id int, name varchar(5)) engine=myisam default charset=UTF8; Query OK, 0 rows affected (0.02 sec)

      mysql> show create table test4 \G * 1. row *

         Table: test4
      

      Create Table: CREATE TABLE test4 ( id int(11) DEFAULT NULL, name varchar(5) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ```

    3. 可以使用alter关键字修改数据表的engine。```sql alter table test4 engine=innodb;

      mysql> show create table test4 \G * 1. row *

         Table: test4
      

      Create Table: CREATE TABLE test4 ( id int(11) DEFAULT NULL, name varchar(5) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ```

    各种存储引擎的特性

    特点 MyISAM InnoDB MEMORY MERGE NDB
    存储限制 64TB 没有
    事务安全 支持
    锁机制 表锁 行锁 表锁 表锁 行锁
    B树索引 支持 支持 支持 支持 支持
    哈希索引 支持
    全文索引 支持 支持
    集群索引 支持
    数据缓存 支持 支持 支持
    索引缓存 支持 支持 支持 支持 支持
    数据压缩 支持
    空间使用 N/A
    内存使用 中等
    批量插入的速度
    外键支持 支持

    参考:深入浅出MySQL