当前位置:网站首页>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服务器上表的方法; |
|---|---|
| 使用场景 | 偶尔的统计分析及手工查询 |
边栏推荐
- 云原生落地进入深水区,博云容器云产品族释放四大价值
- 406-双指针(27. 移除元素、977.有序数组的平方、15. 三数之和、18. 四数之和)
- [project training] details of linear components
- 启发式的搜索策略
- [daily training] 513 Find the value in the lower left corner of the tree
- GINet
- 闫氏DP分析法
- PSP code implementation
- asp. Net file download demo and related problems
- MySQL mvcc multi version concurrency control
猜你喜欢

Configuration and compilation of mingw-w64, msys and ffmpeg

Xxl-sso enables SSO single sign on

初始化层实现

20220621 Three Conjugates of Dual Quaternions

TP6+Redis+think-queue+Supervisor实现进程常驻消息队列/job任务

启发式的搜索策略
![[STL] summary of deque usage of sequential containers](/img/33/65c54d14697ee43b2655ea1255d67d.png)
[STL] summary of deque usage of sequential containers

深度学习系列47:styleGAN总结

MySQL MVCC多版本并发控制

Advanced drawing skills of Excel lecture 100 (VIII) -excel drawing WiFi diagram
随机推荐
Regular expression graph and text ultra detailed summary without rote memorization (Part 1)
Don't look for [12 super easy-to-use Google plug-ins are here] (are you sure you want to take a look?)
307. area and retrieval - array modifiable
C # how to obtain DPI and real resolution (can solve the problem that has been 96)
GINet
Quartz调度框架的学习使用
[project training 10] drawing of arrows
899. 有序队列
20220621 Dual Quaternion
在金融行业做数据产品经理是什么体验
Specific help of OSI layered model to work
Intentional shared lock, intentional exclusive lock and deadlock of MySQL
896. 单调数列
313. super ugly number
896. monotonic sequence
Why does TCP protocol shake hands three times instead of two?
junit单元测试报错org.junit.runners.model.InvalidTestClassError: Invalid test class ‘xxx‘ .No runnable meth
How to verify date format in PHP (regular)
Database principle experiment test questions, about book classification table
[bull Chinese document] queue package used to process distributed jobs and messages in nodejs


