MysqL 的所有存储引擎概述
1. MysqL 存储引擎概述
MysqL 5.7 支持的存储引擎有:InnoDB、MyISAM、MEMORY、CSV、MERGE、FEDERATED 等。从 5.5.5 版本开始,InnoDB 成为 MysqL 的默认存储引擎,也是当前最常用的存储引擎,5.5.5 版本之前,默认引擎为 MyISAM。创建新表时,如果不指定存储引擎,MysqL 会使用默认存储引擎。
MysqL> show variables like 'default_storage_engine';
+------------------------+--------+
| Variable_name | Value |
+------------------------+--------+
| default_storage_engine | InnoDB |
+------------------------+--------+
row in set ( sec)
MysqL> show engines\G
*************************** . row ***************************
Engine: MEMORY
Support: YES
Comment: Hash based, stored in memory, useful for temporary tables
Transactions: NO
XA: NO
Savepoints: NO
*************************** . row ***************************
Engine: CSV
Support: YES
Comment: CSV storage engine
Transactions: NO
XA: NO
Savepoints: NO
*************************** . row ***************************
Engine: MRG_MYISAM
Support: YES
Comment: Collection of identical MyISAM tables
Transactions: NO
XA: NO
Savepoints: NO
*************************** . row ***************************
Engine: BLACKHOLE
Support: YES
Comment: /dev/null storage engine (anything you write to it disappears)
Transactions: NO
XA: NO
Savepoints: NO
*************************** . row ***************************
Engine: InnoDB
Support: DEFAULT
Comment: Supports transactions, row-level locking, and foreign keys
Transactions: YES
XA: YES
Savepoints: YES
*************************** . row ***************************
Engine: PERFORMANCE_SCHEMA
Support: YES
Comment: Performance Schema
Transactions: NO
XA: NO
Savepoints: NO
*************************** . row ***************************
Engine: ARCHIVE
Support: YES
Comment: Archive storage engine
Transactions: NO
XA: NO
Savepoints: NO
*************************** . row ***************************
Engine: MyISAM
Support: YES
Comment: MyISAM storage engine
Transactions: NO
XA: NO
Savepoints: NO
*************************** . row ***************************
Engine: FEDERATED
Support: NO
Comment: Federated MysqL storage engine
Transactions: NULL
XA: NULL
Savepoints: NULL
rows in set ( sec)
每一行的含义大致如下:
创建表时,ENGINE 关键字表示表的存储引擎。如下例子中,表 a 的存储引擎为 InnoDB,表 b 的存储引擎为 MyISAM。
MysqL> create table (id int) ENGINE = InnoDB;
Query OK, rows affected ( sec)
MysqL> create table (id int) ENGINE = MyISAM;
Query OK, rows affected ( sec)
也可以使用 show table status
命令查看表的相关信息。
MysqL> show table status like 'a'\G
*************************** . row ***************************
Name:
Engine: InnoDB
Version:
Row_format: Dynamic
Rows:
Avg_row_length:
Data_length:
Max_data_length:
Index_length:
Data_free:
Auto_increment: NULL
Create_time: -- ::
Update_time: -- ::
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
row in set ( sec)
每一行的含义大致如下:
- Name:表名;
- Engine:表的存储引擎类型;
- Version:版本号;
- Row_format:行的格式
- Rows:表中的行数;
- Avg_row_length:平均每行包含的字节数;
- Data_length:表数据的大小(单位字节);
- Max_data_length:表数据的最大容量;
- Index_length:索引的大小(单位字节);
- Data_free:已分配但目前没有使用的空间,可以理解为碎片空间(单位字节);
- Auto_increment:下一个 Auto_increment 值;
- Create_time:表的创建时间;
- Update_time:表数据的最后修改时间;
- Check_time:使用check table命令,最后一次检查表的时间;
- Collation:表的默认字符集和字符列排序规则;
- Checksum:如果启用,保存的是整个表的实时校验和;
- Create_options:创建表时指定的其他选项;
- Comment:表的一些额外信息。