一、MySQL架构图

图片来源查看官方文档:https://dev.mysql.com/doc/refman/8.0/en/pluggable-storage-overview.html
MySQL中有如下组件:
- 连接池组件:Connetion Pool
- NoSQL接口:CRUD操作
- SQL接口:处理DML、DDL、存储过程、视图、触发器等
- 查询分析器组件:Parser
- 优化器组件:Optimizer
- 缓存组件:Caches & Buffers
- 插件式存储引擎:Storage Engines
- 物理文件:Files & Logs
二、MySQL常用存储引擎
MySQL区别于其他数据库的一个重要特点是支持插件式存储引擎,它是基于表的而不是数据库。
使用命令show engines;
查看MySQL支持的存储引擎
mysql 版本信息 :Server version: 8.0.23 MySQL Community Server - GPL
mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| 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 |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
InnoDB (5.5版本后的默认存储引擎)
- 支持事务
- 行锁设计
- 支持外键
- 支持MVCC(多版本并发控制),实现4种隔离级别
- 表的行按照主键顺序存放
- 最常用的数据库存储引擎
MyISAM (5.5版本前的默认存储引擎)
- 不支持事务
- 表锁设计
- 只缓存索引文件,不缓存数据文件
- 查询速度快
- 可以使用MyISAM pack 工具压缩,但是压缩后表为只读
NDB
- 集群数据库
- 数据放在内存
- 高可用和高并发
Memory
- 数据放在内存
- MySQL临时表会使用这个引擎
- 不支持 text 和 blob 字段,如果临时表有用到这两个类型,会使用MyISAM,而该引擎不缓存数据在内存,所以性能会受影响
Archive
- 只支持INSERT 和 SELECT操作
- 数据压缩后存放
- 适用于数据高速插入和压缩,例如日志的存储
Federated
- 不存放数据,指向远程MySQL的表
Maria
- 用于替换MyISAM
- 支持缓存和索引
- 行锁设计
- 支持MVCC
InnoDB架构

图片来源地址:https://dev.mysql.com/doc/refman/8.0/en/innodb-architecture.html
网友评论