当前位置:网站首页>MySQL(四) — MySQL存储引擎
MySQL(四) — MySQL存储引擎
2022-06-23 06:23:00 【坏蛋呆呆】
目录
一、准备
1、查看MySQL支持什么引擎。
mysql> show engines;
+--------------------+---------+--------------+------+------------+
| Engine | Support | Transactions | XA | Savepoints |
+--------------------+---------+--------------+------+------------+
| MyISAM | YES | NO | NO | NO |
| CSV | YES | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | NO | NO | NO |
| BLACKHOLE | YES | NO | NO | NO |
| MRG_MYISAM | YES | NO | NO | NO |
| InnoDB | DEFAULT | YES | YES | YES |
| ARCHIVE | YES | NO | NO | NO |
| MEMORY | YES | NO | NO | NO |
| FEDERATED | NO | NULL | NULL | NULL |
+--------------------+---------+--------------+------+------------+
2、查看MySQL默认的引擎是什么?
mysql> show variables like '%storage_engine%';
+----------------------------------+--------+
| Variable_name | Value |
+----------------------------------+--------+
| default_storage_engine | InnoDB |
| default_tmp_storage_engine | InnoDB |
| disabled_storage_engines | |
| internal_tmp_disk_storage_engine | InnoDB |
+----------------------------------+--------+二、MyISAM
| 简介 | MySql 5.5之前默认的存储引擎 |
|---|---|
| 组成 | MyISAM存储引擎由MYD和MYI组成 |
| 使用示例 | create table testmysam ( id int PRIMARY key ) ENGINE=myisam; insert into testmysam VALUES(1),(2),(3) |
| 物理结构 | ![]() |
| 特性 | 并发性与锁级别→表级锁 支持全文检索 支持数据压缩,(压缩后,表变为只读,不允许再插入数据) myisampack -r -f testmysam.MYI |
| 使用场景 | 非事务型应用(数据仓库,报表,日志数据) 空间类应用(空间函数、坐标) |
三、InnoDB
| 简介 | MySql 5.5以及以后版本默认存储引擎 |
|---|---|
| 组成 | 由ibd和frm组成 |
| 使用示例 | create table testinnodb (id int PRIMARY key) ENGINE=InnoDB; |
| 物理结构 | ![]() |
| 特性 | Innodb是一种事务性存储引擎 完全支持事务的ACID特性 Redo Log 和 Undo Log Innodb支持行级锁(并发程度更高 |
| 使用场景 | Innodb适合于大多数OLTP应用 |
1、查看是否使用独立表空间
mysql> show variables like 'innodb_file_per_table';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_file_per_table | ON |
+-----------------------+-------+
#####################
ON:独立的表空间:tablename.ibd
OFF:系统表空间:ibdataX
mysql5.6以前默认为系统表空间
系统表空间和独立表空间比较:
1、系统表空间无法简单的收缩文件大小
2、独立表空间可以通过optimize table 收缩系统文件
3、系统表空间会产生IO瓶颈
4、独立表空间可以同时向多个文件刷新数据
建议:Innodb使用独立表空间| MYISAM | InnoDB | |
|---|---|---|
| 主外键 | 不支持 | 支持 |
| 事务 | 不支持 | 支持 |
| 行表锁 | 表锁,即使操作一条记录也会锁住整个表 不适合高并发的操作 | 行锁,操作时只锁某一行,不对其它行有影响 适合高并发的操作 |
| 缓存 | 只缓存索引,不缓存真实数据 | 不仅缓存索引还要缓存真实数据,对内存要求较高,而且内存大小对性能有决定性的影响 |
| 表空间 | 小 | 大 |
| 关注点 | 性能 | 事务 |
| 默认安装 | Y | Y |
四、CSV
| 简介 | 数据以文本方式存储在文件 |
|---|---|
| 组成 | .csv:存储文件内容 .csm:存储表的元数据,如表状态和数据量 .frm:表结构 |
| 使用示例 | create table mycsv(id int not null,c1 VARCHAR(10) not null,c2 char(10) not null) engine=csv; |
| 物理结构 | ![]() |
| 特性 | 以csv格式进行数据存储 所有列都不能为null的 不支持索引(不适合大表,不适合在线处理) 可以对数据文件直接编辑(保存文本文件内容),编辑后需要刷新表flush TABLES; |
五、Memory
| 使用示例 | create table mymemory ( id int,c1 varchar(10),c2 char(10) ) ENGINE=memory; |
|---|---|
| 特性 | memory数据易丢失,所以要求数据可再生 HEAP存储引擎,所以数据保存在内存中 支持HASH索引和BTree索引 所有字段都是固定长度 varchar(10) = char(10) 不支持Blog和Text等大字段 Memory存储引擎使用表级锁 最大大小由max_heap_table_size参数决定 |
| 使用场景 | hash索引用于查找或者是映射表(邮编和地区的对应表) 用于保存数据分析中产生的中间表 用于缓存周期性聚合数据的结果表 |

六、Archive
| 简介 | 以zlib对表数据进行压缩,磁盘I/O更少 数据存储在ARZ为后缀的文件中 |
|---|---|
| 组成 | 由ARZ和FRM组成 |
| 使用示例 | create table myarchive(id int auto_increment not null,c1 VARCHAR(10),c2 char(10), key(id)) engine = archive; |
| 物理结构 | |
| 特性 | 只支持insert和select操作 只允许在自增ID列上加索引 |
| 使用场景 | 日志和数据采集的应用 |
六、Ferderated
| 特性 | 提供了访问远程MySQL服务器上表的方法; |
|---|---|
| 使用场景 | 偶尔的统计分析及手工查询 |
边栏推荐
- Unet代码实现
- 启发式的搜索策略
- The List
- About professional attitude
- 406 double pointer (27. remove elements, 977. square of ordered array, 15. sum of three numbers, 18. sum of four numbers)
- MySQL重做日志 redo log
- redux Actions may not have an undefined “type“ property. Have you misspelled a constant?
- 深度学习系列47:超分模型Real-ESRGAN
- 896. 单调数列
- EndNote20使用教程分享(未完
猜你喜欢

Initialization layer implementation

Idea automatically generates serialVersionUID

In depth learning series 47:stylegan summary

Interpreting the spirit of unity and cooperation in maker Education

【***数组***】

Chrome remove duplicate bookmarks

MySQL重做日志 redo log

Idea installing the cloudtoolkit plug-in

Why does TCP protocol shake hands three times instead of two?

Endnote20 tutorial sharing (unfinished
随机推荐
The List
407-栈与队列(232.用栈实现队列、225. 用队列实现栈)
Idea automatically generates serialVersionUID
【***数组***】
Chrome remove duplicate bookmarks
Verilog syntax explanation
901. 股票价格跨度
产品-Axure9(英文版),原型设计后台动态二级菜单显示内容
Advanced drawing skills of Excel lecture 100 (VIII) -excel drawing WiFi diagram
js 判断两个数组增加和减少的元素
898. 子数组按位或操作
Pspnet complete code implementation
PSP code implementation
[STL] summary of map usage of associated containers
paddle版本问题
TP6 安装拓展
1161 Merging Linked Lists
数据库原理实验测试题,关于图书分类表
[bull Chinese document] queue package used to process distributed jobs and messages in nodejs
How to verify date format in PHP (regular)


