Let's talk about MySQL logical architecture
This article brings you relevant knowledge about mysql, which mainly introduces the related issues of mysql logical architecture. The general architecture is divided into three layers, which are used for connection thread processing, Contains most of mysql core services and storage engines. I hope it will be helpful to everyone.
Recommended learning: mysql learning tutorial
Mysql logical architecture (roughly divided into three layers)
First layer: connection thread processing
Client——>Connection thread processing (connection processing, authorization authentication, security)
The services included are not unique to mysql. They all serve C/S programs or what these programs need (connection processing, authorization authentication, security, etc.)
Second layer: Contains most of mysql core services
- ##Query cache——>Parser——>Optimizer——>Execute query
Query caching, parsing, analysis, optimization, caching, all built-in functions (date, time, mathematical and encryption functions). At the same time, all the functions provided by the storage engine are concentrated in this layer (storage Process, trigger, view) Process: Before parsing the query, the cache must be queried first. The cache can only save the query information and result data. If a query is requested and exists in the cache, no parsing is required. The query is optimized and executed, and the results of the query stored in the cache are directly returned.The third layer: contains the storage engine
- The storage engine is responsible for mysql Data storage and retrieval (similar to the file system under Linux)
Each storage engine has advantages and disadvantages, and the intermediate service layer communicates with the storage engine through APIs , these API interfaces shield the differences between different storage engines and make the query layer as transparent as possible. The storage engine API contains more than a dozen low-level functions, such as executing "Start a transaction" or fetching rows with specific primary keys, but the storage engine generally does not parse SQL (InnoDB will parse foreign key definitions , because it does not implement this function itself), different storage engines will not communicate with each other, but will simply respond to upper-layer server requests.Mysql logical architecture - detailed introduction (divided into eight steps) 1.Connectors
- refers to different prophecies Interaction with SQL
Nactive C API, JDBC, ODBC, .NET, PHP, Python, Perl, Ruby, VB2. Enterprise Management Services & Utilities
- System Management and Control Tools
3. Connection Pool
- Manage buffered user connections, thread processing, etc. Caching requirements are required.
- Responsible for monitoring various requests to MySQL Server, accepting connection requests, and forwarding all connection requests to the thread management module.
- Every client request connected to MySQL Server will be assigned (created) a connection thread to serve it separately, and the connection thread is cached, so there is no need to Client connections are created and destroyed separately, and the main job of the connection thread is to be responsible for the communication between MySQL Server and the client, receive the client's command request, and transmit the result information from the server. The thread management module is responsible for managing and maintaining these connection threads, including the creation of threads. Thread cache, etc.
4.SQL Interface (SQL interface)
- Accepts the user's SQL command and returns the results that the user needs to query. For example, select from is to call SQL Interface
5.Parser (parser)
- When the SQL command is passed to the parser, it will be Verification and parsing, the parser is implemented by Lex and YACC, and is a very long script. In MySQL, we are used to calling all commands sent by the Client to the Server side called queries. In MySQL Server, the connection thread receives the client After receiving a Query on the end, the query will be directly passed to the module responsible for classifying various Queries and then forwarding them to each corresponding processing module
a. Perform semantic and syntactic analysis of SQL statements, decompose them into data structures, then classify them according to the same operation type, and make targeted forwarding to subsequent steps. In the future, the SQL statements will be transmitted and The processing is based on this structure b. If an error is encountered during the decomposition, it means that the sql statement is unreasonable Query Translation, Object Privilege 6.Optimizer (query optimizer) SQL statements will use the query optimizer to optimize the query before querying, which is to optimize the customer The client requests the query. Based on the query statement requested by the client and some statistical information in the database, it is analyzed based on a series of algorithms and an optimal strategy is obtained to tell the subsequent program how to obtain the result of the query statement. The use of "Select-Projection-Join" strategy for query; Access Paths, Statistics 7.Cache and Buffer (query cache) The main function is to submit the client to the Select class query of Mysql The result set returned by the request is cached in memory and corresponds to a hash value of the query. After any data changes occur in the base table of the data obtained by the query, MySQL will automatically invalidate the cache of the query. After reading and writing, In application systems with a very high proportion, Query Cache can significantly improve performance, but of course it consumes a lot of memory. Global and Engine Specific Caches & Buffers 8.pluggable storage Engines Storage engine interface: The most important feature that distinguishes MySQL from other databases is its plug-in table storage engine. MySQL plug-in storage engine architecture provides a series of standard management and service support. These standards have nothing to do with the storage engine itself and may be required by every database system, such as SQL Analyzers and optimizers, etc., while the storage engine is the implementation of the underlying physical structure. Each storage engine developer can develop according to their own wishes. 9.file system File system, data, log (redo, undo) index, error log, query record, slow query, etc. Note: The storage engine is based on tables, not databases Establishment TCP connection——>Verify user——>Create thread to parse SQL——>Generate execution plan——>Open table——>Search buffer to see if the required data page is cached——>Scan from disk Data——>Get data and write to buffer pool——>Return data to client——>Close table——>Close thread——>Close connection Top layer: Client connection 1. Connection processing: The client establishes a TCP connection with the database service layer. The connection management module will establish the connection and request a Connection thread. If there is an idle connection thread in the connection pool, it will be allocated to this connection. If not, a new connection thread will be created to be responsible for this client without exceeding the maximum number of thread connections. 2. Authorization authentication: Before the query operation, the user module needs to be called to perform authorization check to verify whether the user has permission. After passing the authorization, the service will be provided and the connection thread will begin to accept and process the SQL statement from the client Second Layer: Core Service 1. After the connection thread receives the SQL statement, it hands the statement to the SQL statement parsing module for syntax and semantics analyze. 2. If it is a query statement, you can first check whether there is a result in the query cache. If there is a result, it will be returned directly to the client. 3. If there are no results in the query cache, you need to query the database engine layer and send the SQL statement to the optimizer to optimize the query. If it is a table change, the classification is handed over to insert, update, delete. create, alert processing module for processing The third layer: database engine layer 1. Open the table, if Obtain the corresponding lock if necessary. 2. First check whether there is corresponding data in the cache page. If there is, it can be returned directly. If not, read it from the disk. 3. When the corresponding data is found on the disk After that, it will be loaded into the cache, making subsequent queries more efficient. Due to the limited cache, flexible LRU tables are often used to manage cache pages to ensure that the cached data is frequently accessed. 4. Finally, after obtaining the data, return it to the client, close the connection, and release the connection thread. 1. What is a plug-in storage engine The storage engine is to read and write data to the disk. Different storage engines , the read and write operation methods are also different, transactions, locks, etc. are different. Because we have different business needs, there will be many storage engines. In a database, because the storage engine is based on tables, different tables can have Different storage engines allow the storage engine to be loaded into the running MySQL server. This is the plug-in storage engine 2. What is LRU cache Cache elimination mechanism strategy algorithm, because the cache memory is always limited, so some content must be deleted when the cache is full to make room for new content. Under the LRU mechanism, the eliminated data is called useless data. The full name of LRU is Least Recently Used, that is, we think that the data that has been used recently is useful, and the data that has not been used for a long time should be useless. When the memory is full, the data that has not been used for a long time will be deleted first The caching strategy of Ehcache in the JVM includes
For example: select uid,name from user where gender=1;
This query statement first selects based on the statement after where, instead of First query all the tables and then perform gender filtering, and then perform attribute projection based on uid and name, instead of taking out all the attributes and then filtering, and finally connect these two query conditions to generate the final query result
If there is a valid hit query result in the query cache, the query statement can directly fetch data from the query cache. This cache mechanism is composed of a series of small caches, such as table cache, record cache, and Key cache. , permission caching, etc.
Database workflow
FAQ Analysis
Recommended learning:
The above is the detailed content of Let's talk about MySQL logical architecture. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Effective monitoring of Redis databases is critical to maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a powerful utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you seamlessly build monitoring solutions. By studying this tutorial, you will achieve fully operational monitoring settings
