当前位置:网站首页>Do you know what "parts" MySQL contains?
Do you know what "parts" MySQL contains?
2022-07-26 06:54:00 【What is it】
The teacher said :
Develop as a back end ,MySQL It's one of the technologies we use , It is also a high-frequency interview question in the interview , So you know MySQL The basic structure of ? know MySQL Each included " Spare parts " And their role ?
Let's talk about it MySQL The architecture of .
An aerial view , Let's have a basic understanding first 
Yes, nothing wrong , From the above MySQL The logical architecture diagram It is not difficult for us to see what we are familiar with MySQL Can be divided into Server Layer and storage engine layer .
and Server The layer also contains the most , The most important part , It includes connectors 、 The query cache 、 analyzer 、 Optimizer 、 Actuators, etc , cover MySQL Most of the core service functions of , And all the built-in functions ( Such as date 、 Time 、 Mathematical functions, etc ), All cross-storage engine functionality is implemented in this layer , such as stored procedure 、 trigger 、 View etc. .
From the above information, I believe you can also understand Server The importance of layers , The storage engine layer is mainly responsible for the storage and extraction of our data . We all know that MySQL Supports many storage engines , It can be seen that its architecture mode is plug-in , Our most commonly used storage engine is InnoDB, It is from MySQL 5.5.5 Version began to be the default storage engine .
That is, when you create a table and do not specify a storage engine , It will default to InnoDB, Of course, you can also specify the storage engine you want , In the following code block, I have prepared it for the audience master , You can get it on demand
create table indicate (
Field
...
)engine= Storage engine ;
We can also see from the above architecture diagram , Different storage engines correspond to the same Server layer .
Now let's take a look at these one by one ‘‘ Spare parts ’’
The connector
First, we need to connect to the database , At this time, our reception is connector , It is responsible for creating database connections
The connection command is usually written like this :
mysql -h$ip -P$port -u$user -p
Connect... In the command mysql It's a client tool , Used to establish a connection with the server . In the completion of the classic TCP After shaking hands , The connector is about to start authenticating your identity , This is the user name and password you entered .
Later, it is the same as our login system , If the account password is incorrect, it will remind :"Access denied for user" Error of , If the account password is correct, your permission will be verified in the permission table , You can start the operation .
The query cache
After the connection is established , You can do it select Statement . The execution logic will come to the second step : The query cache .
MySQL After getting a query request , I will go to query cache first , Have you executed this statement before . Previously executed statements and their results may be key-value On the form of , Is directly cached in memory .key Is the statement of the query ,value Is the result of a query . If your query can be found directly in this cache key, So this value Will be returned directly to the client .
But the requirements here are very strict , And it's not so easy to use , We should also pay attention to ,MySQL 8.0 Version of the query cache directly removed the entire block , in other words 8.0 It's starting to disappear completely .
Here is a statement that explicitly specifies the use of query caching
select SQL_CACHE * from Team where ID=10;
analyzer
If the query cache is not hit , It's about time to actually execute the statement . First ,MySQL Need to know what you're going to do , So you need to SQL Statement parsing .
The analyzer will treat our SQL The sentence goes on “ Lexical analysis ” , That is to understand our SQL What are the strings inside , What is the .
Next, we need to “ Syntax analysis ”, The parser will follow the grammar rules , Judge the one you typed SQL Does the statement satisfy MySQL grammar .
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near ...
When we see something wrong, we need to consider our own SQL What's wrong with the statement
Optimizer
Through the analyser ,MySQL You know what you're gonna do . Before we start executing , It's also handled by the optimizer .
The optimizer is when there are multiple indexes in a table , Decide which index to use ; There are many. where conditional , First implement that condition ; Or there are multiple table associations in a statement (join) When , Determine the connection order of each table, and so on . The optimizer will treat our SQL Statement optimization , Make it execute faster , After the optimizer phase is complete , The execution of this statement is determined , Then we go to the executor phase .
actuator
MySQL I know what you are going to do through the analyzer , You know what to do with the optimizer , So it goes into the actuator stage , Start statement execution .
At the beginning of execution , Let's first judge what you do to this watch T Do you have permission to execute the query , without , An error with no permissions is returned , If you have authority , Open the table and continue . When I open my watch , The actuator is defined according to the engine of the table , Use the interface provided by the engine .
For example, above us SQL In the table Team in ,ID Field has no index , So the execution process of the actuator is like this :
call InnoDB The engine interface takes the first row of this table , Judge ID Value is 10, If not, skip , If it is, the row will exist in the result set ;
Call the engine interface “ The next line ”, Repeat the same logic of judgment , Until you get to the last row of the table .
The executor returns the record set composed of all the rows that meet the conditions in the traversal process to the client as a result set .
thus , We will take MySQL All of the “ Spare parts ” All introduced .
When you finish reading this article, it is not difficult to find , The most important content has been simplified in the figure we gave , Audience masters can take the picture directly .
======================== Thank you again for watching ========================
边栏推荐
- 曲线曲率展示
- Heap sort
- The creation of "harmonyos" project and the use of virtual machines
- 『期末复习』16/32位微处理器(8086)基本寄存器
- XSS-labs(1-10)闯关详解
- Kubernetes scheduling concept and workflow
- 在第一次使用德国小鸡要注意的地方
- Multi-objective collaborative decision-making in supply chain
- Fastdfs supports dual IP and IPv6
- 浅谈eval与assert一句话木马执行区别
猜你喜欢
![[graduation season _ advanced technology Er] farewell to yourself who has been confused for the past two years. Regroup, junior I'm coming](/img/04/3121514fcd8fcf1c939cbca7f4c67a.jpg)
[graduation season _ advanced technology Er] farewell to yourself who has been confused for the past two years. Regroup, junior I'm coming
![[Star Project] small hat aircraft War (III)](/img/43/af4e923e901c1b2ad32b60c980dcdb.png)
[Star Project] small hat aircraft War (III)

How does the seckill system ensure that the database does not crash and prevent oversold goods

UIToolkit工具模板工程

20000 words will take you from 0 to 1 to build an enterprise level microservice security framework

针对前面文章的整改思路

【毕业季_进击的技术er】送别过去两年迷茫的自己。重整旗鼓,大三我来啦

Introduce you to JVM from architecture

vulnhub Lampião: 1

Which "digital currencies" can survive this winter? 2020-03-30
随机推荐
FastDFS-支持双IP、IPV6
Quick sort
Curve curvature display
Function of hot air pad
『期末复习』16/32位微处理器(8086)基本寄存器
针对前面文章的整改思路
The results of the soft test can be checked, and the entry to query the results of the soft test has been opened in the first half of 2022
IV Actual combat - global unified return result class
MySQL check whether the table is locked
Shell programming
docker修改挂载到宿主机上的mysql配置文件不生效?
从Architecture带你认识JVM
Rust语言- Slice(切片)类型(&[u8])
Downloadutilse tool class without error
Do you think you are a reliable test / development programmer? "Back to the pot"? Surface and reality
字符串和内存函数
2万字带你从0到1搭建一套企业级微服务安全框架
『牛客|每日一题』模板栈
日志轮转logrotate
XSS-labs(1-10)闯关详解