当前位置:网站首页>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服务器上表的方法; |
|---|---|
| 使用场景 | 偶尔的统计分析及手工查询 |
边栏推荐
猜你喜欢

Open source oauth2 framework for SSO single sign on

The illustration shows three handshakes and four waves. Xiaobai can understand them
![[daily training] 513 Find the value in the lower left corner of the tree](/img/97/ab2179d6dbd0536e8cc139659aecc2.png)
[daily training] 513 Find the value in the lower left corner of the tree

QT designer cannot modify the window size, and cannot change the size by dragging the window with the mouse

别找了诸位 【十二款超级好用的谷歌插件都在这】(确定不来看看?)

Swagger3 integrates oauth2 authentication token

Deep learning series 47: Super sub model real esrgan

GINet

Eureka

聚焦行业,赋能客户 | 博云容器云产品族五大行业解决方案发布
随机推荐
Paddle version problem
JUnit unit test reports an error org junit. runners. model. InvalidTestClassError: Invalid test class ‘xxx‘ . No runnable meth
.h5文件忘记数据库名字,使用h5py打印
900. RLE 迭代器
启发式的搜索策略
GIS实战应用案例100篇(七十九)-多规整合底图的制作要点
junit单元测试报错org.junit.runners.model.InvalidTestClassError: Invalid test class ‘xxx‘ .No runnable meth
Page embedded iframe click browser back problem
Traversal of binary tree and related knowledge
Swagger3 integrates oauth2 authentication token
301. 删除无效的括号
Xxl-sso enables SSO single sign on
Intentional shared lock, intentional exclusive lock and deadlock of MySQL
正则表达式图文超详细总结不用死记硬背(上篇)
About Supervision
数据库原理实验测试题,关于图书分类表
Chrome remove duplicate bookmarks
[project training] change of linear arrow
Configuration and compilation of mingw-w64, msys and ffmpeg
900. RLE iterator


