当前位置:网站首页>MYSQL架构——逻辑架构
MYSQL架构——逻辑架构
2022-07-04 22:17:00 【swttws.】
目录
一、整理逻辑架构
MySQL主要体现在存储引擎的架构上,插件式的存储引擎架构将查询处理和其它的系统任务以及数据的存储提取相分离。如下图:

1、连接层
(1)为客户端连接服务,包含本地socket通信和大多数基于客户端/服务端工具实现的类似于tcp/ip的通信;
(2)主要完成连接处理,授权认证,安全处理;
(3)引入线程池,为通过安全认证的客户端提供线程;
(4)同样在该层上可以实现基于SSL的安全链接。服务器也会为安全接入的每个客户端验证它所具有的操作权限。
2、服务层
该层架构主要完成大多数的核心服务功能,如SQL接口,并完成缓存的查询,SQL的分析和优化及部分内置函数的执行。
(1)Management Serveices & Utilities: 系统管理和控制工具 ;
(2)SQL interface :接受用户SQL命令,并返回用户查询结果;
(3)Parser: 解析器:SQL命令解析与验证;
(4) Optimizer: 查询优化器;
(5) Cache和Buffer: 如果查询缓存有命中的查询结果,查询语句就可以直接去查询缓存中取数据。这个缓存机制是由一系列小缓存组成的。比如表缓存,记录缓存,key缓存,权限缓存等 。
3、引擎层
存储引擎层,存储引擎真正的负责了MySQL中数据的存储和提取,服务器通过API与存储引擎进行通信。不同的存储引擎具有的功能不同,这样我们可以根据自己的实际需要进行选取。
4、存储层
数据存储层,主要是将数据存储在运行于裸设备的文件系统之上,并完成与存储引擎的交互。
二、查询SQL执行周期
1、修改配置文件,开启查询缓存
(1)修改配置文件/etc/my.cnf,新增一行:query_cache_type=1
重启MySQL服务
systemctl restart mysqld
2、开启查询执行计划
show variables like '%profiling%';
set profiling=1;
3、执行两次相同查询语句
select * from mydb.mytbl where id=1 ;
4、显示最近执行的SQL语句
show profiles;
5、查询6,7执行计划
(1)6的执行计划
show profile cpu,block io for query 6;
(2)查询7的执行计划
show profile cpu,block io for query 7;
可以发现7执行的编号比6少了很多信息,说明查询语句可以冲从缓存中获取数据,SQL语句必须一致才可以缓存命中,如果对·数据库insert,update,delete,缓存则会失效
三、查询流程
1、mysql客户端与服务端进行连接,发送查询语句,服务端会先检查缓存(query cache),若缓存中有与该查询语句一样的语句,直接返回结果,否则进行语句解析;
2、如果某个查询结果已经位于缓存中,服务器就不会再对查询进行解析、优化、以及执行。它仅仅将缓存中的结果返回给用户即可,这将大大提高系统的性能;
3、语法解析器和预处理:首先mysql通过关键字将SQL语句进行解析,并生成一颗对应的“解析树”;
4、mysql解析器将使用mysql语法规则验证和解析查询;
5、预处理器则根据一些mysql规则进一步检查解析树是否合法,当查询优化器当解析树被认为是合法的了,并且由优化器将其转化成执行计划;
6、一条查询可以有很多种执行方式,最后都返回相同的结果。优化器的作用就是找到这其中最好的执行计划。
7、然后,mysql默认使用的BTREE索引,并且一个大致方向是:无论怎么折腾sql,至少在目前来说,mysql只少用到表中的一个索引。
边栏推荐
- Éducation à la transmission du savoir | Comment passer à un test logiciel pour l'un des postes les mieux rémunérés sur Internet? (joindre la Feuille de route pour l'apprentissage des tests logiciels)
- Introducing QA into the software development lifecycle is the best practice that engineers should follow
- AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
- LOGO特训营 第二节 文字与图形的搭配关系
- Shell 脚本实现应用服务日志入库 Mysql
- Flask 上下文详解
- 【OpenGL】笔记二十九、抗锯齿(MSAA)
- i. Mx6ull driver development | 24 - platform based driver model lights LED
- MD5 tool class
- 嵌入式开发:技巧和窍门——提高嵌入式软件代码质量的7个技巧
猜你喜欢

Use blocconsumer to build responsive components and monitor status at the same time

常用的开源无代码测试工具

2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import “fmt“ func main() { fmt.Pri

Tiktok actual combat ~ the number of comments is updated synchronously

Logo special training camp section III initial creative techniques

Zhiyang innovation signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry

Enabling digital economy Fuxin software attends the BRICs high level Forum on Sustainable Development

Deveco device tool 3.0 release brings five capability upgrades to make intelligent device development more efficient

Challenges faced by virtual human industry

Why is Dameng data called the "first share" of domestic databases?
随机推荐
With this PDF, we finally got offers from eight major manufacturers, including Alibaba, bytek and Baidu
How diff are the contents of the same configuration item in different environments?
Service online governance
Jvm-Sandbox-Repeater的部署
LOGO特訓營 第三節 首字母創意手法
华泰证券是国家认可的券商吗?开户安不安全?
It is said that software testing is very simple, but why are there so many dissuasions?
sqlserver对数据进行加密、解密
Force buckle 2_ 1480. Dynamic sum of one-dimensional array
Logo Camp d'entraînement section 3 techniques créatives initiales
30余家机构联合发起数字藏品行业倡议,未来会如何前进?
The table is backed up in ODPs. Why check m in the metabase_ Table, the logical sizes of the two tables are inconsistent, but the number of
Logo special training camp section II collocation relationship between words and graphics
Redis sentinel simply looks at the trade-offs between distributed high availability and consistency
传智教育|如何转行互联网高薪岗位之一的软件测试?(附软件测试学习路线图)
Sqlserver encrypts and decrypts data
PostgreSQL JOIN实践及原理
Test will: bug classification and promotion solution
繁华落尽、物是人非:个人站长该何去何从
SQL中MAX与GREATEST的区别






