当前位置:网站首页>MySQL architecture

MySQL architecture

2022-06-24 01:34:00 Xiao Wange

mysql8.0 Architecture

The picture comes from the Internet

Look at the picture mysql Service is a c/s framework It is to use c and c++ Developed

Connectors End

Can pass , Various clients , link mysql The server Such as mysql command , Various apl etc.

server End

It is divided into many modules

Link layer

1 Provide link agreement TCP/IP The local socket

2 User name password verification ( The authentication database through the authorization table is started , The authorization table will be loaded into memory mysql.user mysql.db mysql.table_priv mysql.column_priv)

3 Provide link thread

View linked threads show processlist;

View all threads in the background select * from performance_schema.threads\G

sql layer

sql Thread receiving link thread

Preprocessing (lex) grammar , semantics ( What kind of statements are ), jurisdiction ( Do you have permission to access the library or table ) Check

analysis (yacc) Generate parse tree (ast Abstract syntax tree )

Optimize Logic optimization Equivalent transformation based on relational algebra , In physical optimization Refer to statistics ( It describes , The distribution of data , Some status of the index , Roughly record how many lines there are in the table ) And some optimizer algorithms , Cost assessment , Generate execution plan (explain)

 Description of Statistics 
 The statistics record   The state of the table ,  Table name   data row   Data distribution   Index status information ...
 The statistics are mysql Collected regularly   Through some parameter indexes   Not collected in real time 
mysql.innodb_index_stats
mysql.innodb_table_stats
# problem   One sql The statement ran well yesterday (0.01 second ) , Suddenly it slows down (2min)?  Why? 
 Due to inaccurate statistical information , It is caused by not going through the index 
 You can force a re collection by command   There is also parameter control 
analyze teble  Library name . Table name ;
 perhaps  optimize table  Library name . Table name ; # Command lock table   Use caution 

Engine layer

io Thread receive sql Threads

mysql Dealing with disks is similar to linux File system

The picture is from mysql Official website

innodb Storage engine is divided into memory structure and disk structure

Macro structure of storage

stay mysql In a database , It is a directory in the system

stay mysql One of the tables Corresponds to one of the operating systems .ibd file (8.0)

In the operating system, you can use ibd2sdi file name You can view the files

 In the table   data row  +  Metadata ( Table properties , Columns of the table ( Column properties ), Table name )
mysql8.0 How tables are stored   The data of each table is stored in ibd In file 
mysql5.7 How tables are stored 
 data row  ibd file 
 Source data  frm +ibdata1( The overall )  file 
Online DDL  It will be faster 

8.0 New features understanding

metdata  Structural changes 
5.7 Version of the problem 
 Two sets of data dictionary information server layer  .frm innodb The data dictionary 
DDL Unable to atomize  ( When deleting two tables , Not together )
frm and innodb Layers will be inconsistent 
 Concurrency needs to be handled with care (MDL,dict_sys::mutex,dict_sys::rw_lock)
 The crash cannot be recovered 
8.0 New characteristics 
 Support transactional DDL, Crash can be rolled back , To ensure consistency ,
 Keep only one copy of the data dictionary information , To cancel the frm The data dictionary 
 The data is all in the InnoDB In the table 
 Adopt sleeve locking mechanism , Manage concurrent access to data dictionaries (DML)
 all-new plugin Support 
8.0.17 Then add clone plugin, Better support MGR InnoDB Clustre Node management of 
 The secure encryption method changes 
 Change the encryption method to caching_sha2_password
SSL  Will support to TLSv1.3 edition .
 Changes in user management and authentication methods 
 Change the authorization method 
 Join in role Role permissions 
 Add more permissions 
cache&&Buffer The change of 
 To cancel the Query Cache
 The result of the query is cached   You will make a query statement hash  The result is key  If you add the query criteria   The cache will not hit 
mysql The query cache for is not a cache execution plan , It's a query and its result set , This means that only the same query operation can hit the cache , hide mysql The query hit rate is very low 
oracle  What is cached is the execution plan   Reduce understanding of the process .

mysql example

mysqld Daemon + Master Threa + Worker Threads + Pre allocated memory

mysql Memory structure 
global buffers( overall situation )
innodb_buffer_pool( You can set the physical memory %50-%75): Data buffer 
innodb_log_buffer: Log buffer 
key_buffer
table_cache
session buffers( Each session is used independently )
read_buffer
read_fnd_buffer
sort buffer
join buffer
tmp table
binlog_cache

mysql Thread in 
master thread     Function as the core background process , Responsible for global management data refresh and data consistency processing 
io thread         Responsible and disk io Interaction  (read io write io insert buffer log io)  Related parameters inndbo_read_io_threads, inndbo_write_io_threads
Purge thread      effect  UNDO Page recycling   Parameters  innodb_purge_threads
page cleaner      effect   Dirty page refresh thread   Default 1  Maximum 64  Parameters  innodb_page_cleaners
other threads
原网站

版权声明
本文为[Xiao Wange]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/11/20211117102012679G.html