拆件式存储引擎是MySQL数据库最重要的特性之一。
查看当前MySQL支持的引擎类型。
show engines \G*************************** 1. row ***************************Engine: InnoDBSupport: DEFAULTComment: Supports transactions, row-level locking, and foreign keysTransactions: YESXA: YESSavepoints: YES*************************** 2. row ***************************Engine: MRG_MYISAMSupport: YESComment: Collection of identical MyISAM tablesTransactions: NOXA: NOSavepoints: NO*************************** 3. row ***************************Engine: MEMORYSupport: YESComment: Hash based, stored in memory, useful for temporary tablesTransactions: NOXA: NOSavepoints: NO*************************** 4. row ***************************Engine: BLACKHOLESupport: YESComment: /dev/null storage engine (anything you write to it disappears)Transactions: NOXA: NOSavepoints: NO*************************** 5. row ***************************Engine: MyISAMSupport: YESComment: MyISAM storage engineTransactions: NOXA: NOSavepoints: NO*************************** 6. row ***************************Engine: CSVSupport: YESComment: CSV storage engineTransactions: NOXA: NOSavepoints: NO*************************** 7. row ***************************Engine: ARCHIVESupport: YESComment: Archive storage engineTransactions: NOXA: NOSavepoints: NO*************************** 8. row ***************************Engine: PERFORMANCE_SCHEMASupport: YESComment: Performance SchemaTransactions: NOXA: NOSavepoints: NO*************************** 9. row ***************************Engine: FEDERATEDSupport: NOComment: Federated MySQL storage engineTransactions: NULLXA: NULLSavepoints: NULL
创建表示可以使用
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: test4Create Table: CREATE TABLE
test4(idint(11) DEFAULT NULL,namevarchar(5) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ```可以使用alter关键字修改数据表的
engine。```sql alter table test4 engine=innodb;mysql> show create table test4 \G * 1. row *
Table: test4Create Table: CREATE TABLE
test4(idint(11) DEFAULT NULL,namevarchar(5) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ```
各种存储引擎的特性
| 特点 | MyISAM | InnoDB | MEMORY | MERGE | NDB |
|---|---|---|---|---|---|
| 存储限制 | 有 | 64TB | 有 | 没有 | 有 |
| 事务安全 | 支持 | ||||
| 锁机制 | 表锁 | 行锁 | 表锁 | 表锁 | 行锁 |
| B树索引 | 支持 | 支持 | 支持 | 支持 | 支持 |
| 哈希索引 | 支持 | ||||
| 全文索引 | 支持 | 支持 | |||
| 集群索引 | 支持 | ||||
| 数据缓存 | 支持 | 支持 | 支持 | ||
| 索引缓存 | 支持 | 支持 | 支持 | 支持 | 支持 |
| 数据压缩 | 支持 | ||||
| 空间使用 | 低 | 高 | N/A | 低 | 低 |
| 内存使用 | 低 | 高 | 中等 | 低 | 高 |
| 批量插入的速度 | 高 | 低 | 高 | 高 | 高 |
| 外键支持 | 支持 |
参考:深入浅出MySQL
