当前位置:网站首页>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服务器上表的方法; |
|---|---|
| 使用场景 | 偶尔的统计分析及手工查询 |
边栏推荐
- 316. 去除重复字母
- Vs2013 ffmpeg environment configuration and common error handling
- Chrome remove duplicate bookmarks
- 315. calculate the number of elements on the right that are smaller than the current element
- C DPI adaptation problem
- Advanced drawing skills of Excel lecture 100 (VIII) -excel drawing WiFi diagram
- 深度学习系列47:超分模型Real-ESRGAN
- [STL] unordered of associated container_ Map Usage Summary
- RFID数据安全性实验:C#可视化实现奇偶校验、CRC冗余校验、海明码校验
- Summarized benefits
猜你喜欢

U-Net: Convolutional Networks for Biomedical Image Segmentation

MySQL MVCC多版本并发控制

MySQL redo log redo log

直播回顾 | 传统应用进行容器化改造,如何既快又稳?
![[STL] summary of map usage of associated containers](/img/1d/1b6488ea47face0548500b1e1ec60d.png)
[STL] summary of map usage of associated containers

Eureka

Analysis of personalized learning progress in maker Education

GINet

406 double pointer (27. remove elements, 977. square of ordered array, 15. sum of three numbers, 18. sum of four numbers)
![[STL] summary of deque usage of sequential containers](/img/33/65c54d14697ee43b2655ea1255d67d.png)
[STL] summary of deque usage of sequential containers
随机推荐
406-双指针(27. 移除元素、977.有序数组的平方、15. 三数之和、18. 四数之和)
The List
How to migrate virtual machines from VirtualBox to hype-v
[project training 10] drawing of arrows
898. 子数组按位或操作
Open source oauth2 framework for SSO single sign on
Why does TCP protocol shake hands three times instead of two?
Badly placed()'s problem
初始化层实现
Learning and using quartz scheduling framework
直播回顾 | 传统应用进行容器化改造,如何既快又稳?
Xshell7 Download
Interpreting the spirit of unity and cooperation in maker Education
306. Addenda
NPM download error NPM err code error
pspnet完整代码实现
[shell] tree command
Summarized benefits
Initialization layer implementation
Swagger3 integrates oauth2 authentication token


