MySQL architecture understanding

 

1.MySQL layered

MySQL is divided into two layers: Server layer and the storage engine.

 

2.Server layer

  • Connector: connection management authority verification.

  • Query cache: cache hit directly return the query results.

  • Analyzer: Analyze syntax.

  • Optimizer: execution plan, select the index.

  • Actuator: indexing operation returns the result.

 

3. Storage Engine

  • Storage engine is responsible for data storage and retrieval, which is a plug-in architecture. InnoDB in MySQL5.5 version became the default storage engine.

  • MySQL storage engine, there are three commonly used: InnoDB, MyISAM, Memory.

    • InnoDB: support services, support for foreign keys, a clustered index, the data and index files are tied together. You must have a primary key, the primary key index of the most efficient. But requires two auxiliary index query, the first query to the primary key, and then query the data by primary key, it does not support full-text indexing.

    • MyISAM: not support transactions, foreign keys are not supported, non-clustered index, the data file and the index are separated, the index pointer stored in the data file. Primary key index and a secondary index is independent, MyISAM InnoDB than the query efficiency, so does the time separating read and write the general shots selected library InnoDB, MyISAM made from the library.

    • Memory: file data stored in the cache, a relatively large defects. If an exception Mysqld process occurs, restart or shut down these data will be lost.

 

Execution of 4.SQL

  • The first step: client connections on MySQL database connectors, connector links to get permission to maintain, if not used for a long time will be disconnected, this time is controlled by wait_timeout.

  • The second step: the client sends to the database sql statement, this time will detect whether the sql query cache checks performed before, if you do it simply returns the cached data to the client, of course, as long as the cache update will fail. So frequently updated table is not recommended to use the query cache, query cache can be specified by SQL_CACHE.

  • The third step: when the type of the query cache misses, the analyzer will begin to function, the parser will judge sql statement: select, insert, update, analyze syntax is correct.

  • The fourth step: The optimizer will decide what order to use the index and join the index table and the sql statement.

  • Step Five: Actuators sql, call storage engine interface, scanning or traversing table update data inserted.

 

5.MySQL log

  • MySQL has two important log: redolog and binlog. redolog belonging innodb log, binlog log belongs to sever the layer.

  • redolog log:

    • redolog also known as redo logs, change records for transaction operations, value before and after the changes and modify records, regardless of whether or not to submit the transaction will be recorded.

    • Database restart recovery will be used to ensure data integrity redolog, redolog fixed size, so the latter overwrite the previous log log.

  • binlog log:

    • binlog also known as archive log that records all changes in the database.

    • binlog is added in the form of log, the log will not cover the back of the front of the log.

  • Database update process

    • Update process: reading the corresponding data to the memory -> update data -> Write redolog Log -> redolog PREPARE state -> write log binlog -> commit the transaction -> redolog state commit, official data is written to the log file.

    • reolog's submission is "two-phase commit."

    •  

 

 

 

 Note: The main contents from the public No. "Jiangnan a little rain."

Guess you like

Origin www.cnblogs.com/wuchangliang/p/11489273.html