当前位置:网站首页>The first day of reading mysql45
The first day of reading mysql45
2022-06-25 16:24:00 【Hurry to Friday】

The permission verification of the connector part is just whether the person has permission to log in ? It involves whether the access user has permission to access sql Table used in ?
Query cache part , How to judge what to do sql It's in the cache ?sql Save all the statements and compare them ?
What does the optimizer optimize ? and sql What is the difference between optimization ? Be similar to java Instruction rearrangement in ?
The actuator operates the engine , About how to operate ?
In what form is the data stored in the storage engine ?
Broadly ,mysql Can be divided into server Layer and engine layer
mysql There are many cryptographic functions in , however mysql8 Many encryption functions have been removed from .
Different storage engines' tables access data in different ways , Functions are also different , When creating tables , use engine=InnoDB Specify the engine of the table , The default is InnoDB engine .
Before using the database, you need to log in to the database , This is the time to use The connector . The connector is responsible for establishing a connection with the client , Maintenance connection , Access permissions , Manage connections .
After success , The obtained permission will always be used in this connection , If the current connection is still valid , The user's permission is modified , You need to disconnect and reconnect to use the new permissions .
If after connection , No tasks performed , You'll be idle , Use show processlist Command to view the current and using database connections . The following screenshots :

Command The value in the column is sleep It means it is idle , Idle time exceeds wait_timeout The connection will be automatically disconnected after time , You can see wait_timeout Configured time :
But here 7200 I don't know what it is , Normally, it should be seconds , If it's minutes, it's 120 Hours ( It's not bullshit ), The unit should be seconds , That's it 2 Hours .
A long connection : After the client connects to the database , The request will continue ; Short connection refers to the connection with the database , Idle after just a few requests .
But long connections can be expensive mysql The memory occupied by , because mysql The memory during execution is placed in the connection object , Only after the connection is disconnected , To clear the memory .
If the long connection persists , As a result, more and more memory will be used , Killed by the system . From a phenomenological point of view mysql Because of the abnormal restart .
How to solve the problem of mysql Restart problem ?
1. Regularly disconnect long connections , Free memory , Then reconnect .
2. It is possible to complete the execution of a project that consumes a lot of resources sql after , By calling mysql_reset_connection To reinitialize the connection resources , After calling , Will free up memory , The cache will also fail , Return to the state where the connection was started .
The frequency of query cache invalidation is very high , An update to a table will invalidate all cached records on the table , If a table is rarely updated , Insert, etc , Suitable for caching , Such as configuration tables .
Caching is based on query statements hash As key, Query results as value, With key-value Form to save , But if sql The case of the statement has changed , Or add notes , Lead to sql Of the statement hash The value has changed , Will result in no cache hit .
mysql8 Can be configured before query_cache_type Parameter disable query cache ,mysql8 The function of whole block query cache is deleted .
analyzer
A miss in the query cache will only , The parser will start to work . First of all “ Lexical analysis ”, It will write you select Identify this query keyword , Will write in from hinder week The identification is the table name
hold id Identify Columns id...; After lexical analysis of each keyword , It will be parsed , Judge whether there is a problem in grammar , Usually they meet “You have an error in your SQL syntax” Report errors . Namely
There is a problem in grammar .
Optimizer
After the analyzer ,mysql Will know you sql What exactly do you want to check , The optimizer optimization processing of the optimizer is also required after the actual execution . When the table has multiple indexes , The optimizer decides which indexes to use ,
Or there's a join The operation of the table , The optimizer will determine the priority according to what conditions to associate .
select *
from week w
join week w2 on w2.id = w.id
where w.id = 2
and w2.id = 6
You can start with w.id = 2 Conditions to w Query the values in the table , Go back and w2 Tables are associated , Re execution w2.id=6, To w2 Find... In the table id be equal to 6 The data of ;
You can also start with w2.id=6 Go first to w2 Find... In the table id be equal to 6 Value , Go back and w Tables are associated , find w.id=2 Value .
Although the execution result is the same , But the execution efficiency may be different ( This is the same table used to save time , Different watches should be used ). The role of the optimizer is to decide which execution scheme to adopt .
actuator
After going through the optimizer , The actuator is ready to start execution
select *
from week w
where w.id =6
Before starting the query , First, query whether you have permission for this table , Do not have permission to directly throw an error , If so, continue to carry out . Call the engine interface used to query .
1. call InnoDB The engine interface queries the first row of table data , Judge id Is the value equal to 6, If yes, put it in the result set , No, just skip
2. Call the engine interface to fetch the next row of data , Judge again
3. Execute until the last row of the table data , Return the data in the result set .
If the column to be queried is indexed , Would call InnoDB Engine “ Take the first line that satisfies the condition ” Interface , Then go to the loop call “ That satisfies the next row ”;
边栏推荐
- 一文带你搞懂 JWT 常见概念 & 优缺点
- GO语言-什么是临界资源安全问题?
- Flutter textfield setting can input multiple lines
- Dino: Detr with improved detecting anchor boxes for end to end object detection
- GO语言-锁操作
- Constructor Pattern
- Catheon Gaming任命Activision Blizzard前亚太区负责人Mark Aubrey担任首席执行官
- Geographic location data storage scheme - redis Geo
- Analysis of the concept of metacosmic system
- Consumer and producer cases of inter thread synchronization (condition variable)
猜你喜欢

Bugly hot update usage
Inter thread synchronization semaphore control

加密潮流:时尚向元宇宙的进阶

Alvaria宣布客户体验行业资深人士Jeff Cotten担任新首席执行官

Navicat Premium 15 for Mac(数据库开发工具)中文版

AutoK3s v0.5.0 发布 延续简约和友好
Classic deadlock scenario of multithreading and its solution (philosopher dining problem)
Consumer and producer cases of inter thread synchronization (condition variable)

Advanced SQL statement 1 of Linux MySQL database

The paid video at station B caused the up master to lose more than ten thousand fans
随机推荐
JS add custom attributes to elements
Leetcode topic [array]-34- find the first and last positions of elements in a sorted array
Blue Bridge Cup - practice system login
Dino: Detr with improved detecting anchor boxes for end to end object detection
Time wheel and implementation analysis of time wheel in go zero
Converting cifar10 datasets
[problem solving] dialogfragment can not be attached to a container view
数字经济时代文化消费新特征
Advanced SQL statement 1 of Linux MySQL database
Vscode有什么好用的插件?
f_ Read function [easy to understand]
Summary of 2022 spring moves of ordinary people (Alibaba and Tencent offer)
心樓:華為運動健康的七年築造之旅
10 Super VIM plug-ins, I can't put them down
Reverse series to obtain any wechat applet code
This article will help you understand the common concepts, advantages and disadvantages of JWT
Beginner bug set
Read the configuration, explain the principle and read the interview questions. I can only help you here...
Detailed explanation of IVX low code platform series -- Overview (I)
Take you to the open source project of smart home: the preliminary configuration of zhiting home cloud and home assistant+ homebridge