MySQL series: 4 Architecture Architecture

Straight to the point

         Like most systems, mysql also follows the C/S architecture model for external services. Its necessary components are: MySQL server—mysql server, client programs—client programs, and MySQL non-client programs—non-client programs. The overall application architecture is as follows.

 

Client Programs

The client program is used to connect to the server and obtain, modify, add, and delete data. Commonly used ones are:

  1. mysql: Issue queries and view results. ---Initiate queries and view results;
  2. mysqladmin: Administer the server.—Management server program;
  3. mysqlcheck: Check the integrity of database tables.—Check the integrity of database tables;
  4. mysqldump: Create logical backups.—Create logical backups;
  5. mysqlimport: Import text data files.—Import data files;
  6. mysqlshow: Show database, table, and column information.—View database, table, and column information;
  7. mysqlslap: Emulate client load.—simulate client load.

Administrative and Utility Programs

         Non-client programs are used to directly access data without going through a link. Commonly used are:

  1. innochecksum: Check an InnoDB tablespace file offline.—Check the InnoDB tablespace file offline;
  2. mysqldumpslow: Summarize the slow query log files.—Query the slow query log of mysql;
  3. mysqlbinlog: Display the binary log files.—View the binary log

mysql server

    Server process. Refers to a process called mysqld , which is a single-process multi-threaded application (unix system) . Used to manage data access and storage, support concurrent client links, support multiple storage engines, and support transactional/non-transactional tables. The architecture of the mysqld server process will be described in detail later.

Server-side architecture

         The mysqld service program is logically divided into three parts : the connection layer, the SQL layer, and the storage layer . The connection layer is used to handle access links in various ways (TCP/IP, unix socket, etc.); the SQL layer is used to process SQL requests submitted by client programs; the storage layer is used to manage the storage of data, including different storage engines and different The storage method (in-memory or file), etc.;

 

Connection Layer

         The connection layer accepts connections from applications over several communication

protocols:

• TCP/IP

• UNIX sockets

• Shared memory

• Named pipes

       The connection layer is used to receive connection requests from different applications/different protocols. The allowed communication protocols are: TCP/IP, unix domain socket (like unix), shared memory (windows), named pipe (windows);

SQL layer

         SQL layer users process various SQL requests after connection, including:

  • Authorization and parser授权与解析: The parser validates the correct syntax, and then authorization verifies that the connected user is allowed to run a particular query.
  • Optimizer优化: Creates the execution plan for each query, which is a step-by-step instruction set on how to execute the query in the most optimal way. Determining which indexes are to be used, and in which order to process the tables, is the most important part of this step.

The optimizer creates an execution plan for each query (a series of sequential instruction sets are used to indicate how to execute the query in an optimal way). Used to add the explain keyword before the SQL statement to view the execution plan created by the system for the SQL statement;

 

  • Query execution: Fulfills the execution plan for each query;
  • Query cache 查询缓存: Optionally configurable query cache that can be used to memorize (and immediately return) executed queries and results;

It is used to cache the query results in the memory, and the same SQL can be used to obtain the results directly in the memory.

  • Query logging: Can be enabled to track executed queries

According to the above description, the execution flow of a SQL statement in mysql is as follows:

 

storage layer

         MySQL supports different types of storage (storage engines), and supports storing data in different media (memory-memory, disk disk, network-network, etc.);

other

Storage engine

简介:Storage engines are server components that act as handlers for different table types.

         The storage engine is used to store data, obtain data, and find data through indexes.

MySQL disk space usage

MySQL's use of disk space is shown in the figure below. A mysqld instance installation includes executable program files, executable program log files, and mysqld data directories; among them, the mysqld data directory includes: server log files, InnoDB log files, data directories (triggers, data and index files, data Format file) and so on.

 

MySQL memory usage

MySQL memory is divided into two categories: Global and session. The global global level is shared among all threads of the process; the session session level is allocated separately for each thread, and the thread creation and destruction are dynamically allocated and destroyed.

MySQL plug-in interface

         The MySQL plug-in API allows dynamic loading/unloading of server-side components, such as storage engines, full-text index parsers, etc.;

to sum up

         MySQL's hierarchical design maximizes the decoupling of various functional components. Similar to the five-layer communication protocol stack in the communications industry, each layer is independently responsible for its own function, and the lower layer provides services to the upper layer without the need for upper layer details.

Guess you like

Origin blog.csdn.net/zhaogang1993/article/details/96604194