当前位置:网站首页>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 ========================
边栏推荐
- 你了解MySQL都包含哪些“零件“吗?
- 28. Implement strstr() implement strstr()
- Is the passenger flow always low? There is something wrong with the location of your store!
- opengauss简易版安装报错
- Quick sort
- 10 papers of ant security laboratory were included by ccf-a top meeting to explore the realization of AI credibility from the perspective of algorithm
- 排序问题:冒泡排序,选择排序,插入排序
- "Niuke | daily question" inverse Polish expression
- 2万字带你从0到1搭建一套企业级微服务安全框架
- Go language configuration vscade
猜你喜欢

Proxyman, a native high-performance packet capturing tool, is for you who love learning

"Final review" 16/32-bit microprocessor (8086) basic register

Is the passenger flow always low? There is something wrong with the location of your store!

MySQL基础篇(二)-- MySQL 基础

Display Chinese characters in uitoolkit

【数据库】CTE(Common Table Expression(公共表表达式))

"Niuke | daily question" inverse Polish expression

【Star项目】小帽飞机大战(三)

UIToolkit工具模板工程

『期末复习』16/32位微处理器(8086)基本寄存器
随机推荐
Use and analysis of show profile optimized by MySQL
Rust语言- Slice(切片)类型(&[u8])
MySQL table write lock
Can you learn fast and well with dual stream network? Harbin Institute of Technology & Microsoft proposed a distillation dual encoder model for visual language understanding, which can achieve fast an
Resume considerations
Proxyman, a native high-performance packet capturing tool, is for you who love learning
优炫数据库JDBC打开日志方式有哪些
28. Implement strStr()实现 strStr()
[database] CTE (common table expression)
Differences and relations between varchar and nvarchar in database
Quick sort
Multi-objective collaborative decision-making in supply chain
MySQL table read lock
堆排序(heap-sort)
【Star项目】小帽飞机大战(四)
【无标题】转载
UIToolkit中显示汉字
【数据库】CTE(Common Table Expression(公共表表达式))
Is the passenger flow always low? There is something wrong with the location of your store!
供应链的多目标协同决策