wiki/运维/数据库/MySQL/mysql笔记/Ⅲ、存储引擎.md
2025-01-02 10:46:09 +08:00

52 lines
3.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

截止到服务器程序完成了查询优化为止还没有真正的去访问真实的数据表MySQL服务器把数据的存储和提取操作都封装到了一个叫存储引擎的模块里物理上如何表示记录怎么从表中读取数据怎么把数据写入具体的物理存储器上这都是存储引擎负责的事情我们可以为不同的表设置不同的存储引擎不同的表可以有不同的物理存储结构不同的提取和写入方式。
## 常用存储引擎
| **存储引擎** | **描述** |
| --- | --- |
| ARCHIVE | 用于数据存档(行被插入后不能再修改) |
| BLACKHOLE | 丢弃写操作,读操作会返回空内容 |
| CSV | 在存储数据时,以逗号分隔各个数据项 |
| FEDERATED | 用来访问远程表 |
| InnoDB | 具备外键支持功能的事务存储引擎 |
| MEMORY | 置于内存的表 |
| MERGE | 用来管理多个MyISAM表构成的表集合 |
| MyISAM | 主要的非事务处理存储引擎 |
| NDB | MySQL集群专用存储引擎 |
## 相关操作
##### 查看当前服务器程序支持的存储引擎
```shell
SHOW ENGINES;
```
回显(字段说明support[是否支持]Transactions[是否支持事务]XA[是否支持分布式事务]Savepoints[是否支持事务回滚])
```shell
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| MyISAM | YES | MyISAM storage engine | NO | NO | NO |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| ARCHIVE | YES | Archive storage engine | NO | NO | NO |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
```
##### 创建表时指定存储引擎
```shell
CREATE TABLE 表名(
建表语句;
) ENGINE = 存储引擎名称;
```
##### 修改表的存储引擎
```shell
ALTER TABLE 表名 ENGINE = 存储引擎名称;
```
##### 查看表结构
```shell
SHOW CREATE TABLE 表名\G
```