Table of Contents
mysql architecture
Home Database Mysql Tutorial Detailed introduction to mysql theory and basic knowledge

Detailed introduction to mysql theory and basic knowledge

Jun 10, 2021 am 09:27 AM
mysql

This article will give you a detailed introduction to mysql theory and basic knowledge. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

Detailed introduction to mysql theory and basic knowledge

mysql architecture

1. Network connection layer

Client Connectors: Provided Built-in support for MySQL server. Currently, almost all mainstream server-side programming technologies are supported, such as common Java, C, Python, .NET, etc., which establish connections with MySQL through their respective API technologies

2. Service layer (MySQL Server)

The service layer is the core of MySQL Server and mainly includes six parts: system management and control tools, connection pool, SQL interface, parser, query optimizer and cache.

Connection Pool: Responsible for storing and managing the connection between the client and the database. One thread is responsible for managing one connection.

System management and control tools (Management Services & Utilities): such as backup and recovery, security management, cluster management, etc.

SQL Interface (SQL Interface): used to accept various types of data sent by the client SQL command and returns the results that the user needs to query. Such as DML, DDL, stored procedures, views, triggers, etc.

Parser (Parser): Responsible for parsing the requested SQL to generate a "parse tree". Then further check whether the parse tree is legal according to some MySQL rules.

Query Optimizer (Optimizer): When the "parse tree" passes the parser grammar check, it will be handed over to the optimizer to convert it into an execution plan, and then interact with the storage engine.

select uid,name from user where gender=1;

Select-》Projection-》Join strategy

1)select first selects based on the where statement, not a query Extract all the data and then filter it

2) The select query performs attribute projection based on uid and name, not all fields

3) Connect the previous selection and projection to finally generate the query result

Cache (Cache&Buffer): The caching mechanism is composed of a series of small caches. For example, table cache, record cache, permission cache, engine cache, etc. If the query cache has a hit query result, the query statement can directly fetch data from the query cache.

3. Storage Engine Layer (Pluggable Storage Engines)

The storage engine is responsible for the storage and extraction of data in MySQL, and interacts with the underlying system files. The MySQL storage engine is plug-in. The query execution engine in the server communicates with the storage engine through an interface. The interface shields the differences between different storage engines. There are many storage engines now, each with its own characteristics. The most common ones are MyISAM and InnoDB.

4. System File Layer (File System)

This layer is responsible for storing database data and logs on the file system and completing the interaction with the storage engine. , is the physical storage layer of files. Mainly includes log files, data files, configuration files, pid files, socket files, etc.

Log file

Error log(Error log)

Enabled by default, show variables like '%log_error%'

General query log ( General query log)

Records general query statements, show variables like '%general%';

Binary log (binary log)

Records changes performed on the MySQL database operation, and records the occurrence time and execution time of the statement; however, it does not record select, show, etc. SQL that does not modify the database. Mainly used for database recovery and master-slave replication.

show variables like '%log_bin%'; //Whether to enable it

show variables like '%binlog%'; //Parameter view

show binary logs;// View the slow query log file

Query log (Slow query log)

Records all query SQL whose execution time has expired. The default is 10 seconds.

show variables like '%slow_query%'; //Whether to enable it

show variables like '%long_query_time%'; //Duration

Configuration file

Used to store all MySQL configuration information files, such as my.cnf, my.ini, etc.

Data file

db.opt file: records the default character set and verification rules used by this library.

frm file: stores metadata (meta) information related to the table, including definition information of the table structure, etc. Each table will have a frm file.

MYD file: It is dedicated to the MyISAM storage engine and stores the data of the MyISAM table. Each table will have a .MYD file.

MYI file: It is dedicated to the MyISAM storage engine and stores index-related information of the MyISAM table. Each MyISAM table corresponds to a .MYI file.

ibd file and IBDATA file: store InnoDB data files (including indexes). The InnoDB storage engine has two table space modes: exclusive table space and shared table space. Exclusive table spaces use .ibd files to store data, and each InnoDB table corresponds to one .ibd file. Shared table spaces use .ibdata files, and all tables use one (or multiple, self-configured) .ibdata files.

ibdata1 file: system table space data file, which stores table metadata, Undo logs, etc.

ib_logfile0, ib_logfile1 files: Redo log log files.

pid file

The pid file is a process file of the mysqld application in the Unix/Linux environment. Like many other Unix/Linux server programs, it stores its own process id.

socket file

The socket file is also available in the Unix/Linux environment. Users can directly use Unix Socket to connect to the client in the Unix/Linux environment without going through the TCP/IP network. Connect to MySQL.

InnoDB and MyISAM

Transactions and foreign keys

InnoDB supports transactions and foreign keys, with security and integrity, suitable for a large number of Insert or update operation

MyISAM does not support transactions and foreign keys. It provides high-speed storage and retrieval, suitable for a large number of select query operations

Lock mechanism

InnoDB supports row-level locking and locks specified records. Locking is implemented based on index.

MyISAM supports table-level locking, locking the entire table.

Index structure

InnoDB uses a clustered index (clustered index). The index and records are stored together, caching both the index and the records.

MyISAM uses non-clustered index (non-clustered index), and the index and record are separated.

Concurrency processing capability

MyISAM uses table locks, which will lead to a low concurrency rate of write operations, no blocking between reads, and blocking of reads and writes.

InnoDB read and write blocking can be related to the isolation level, and multi-version concurrency control (MVCC) can be used to support high concurrency

Storage files

InnoDB The table corresponds to two files, a .frm table structure file and an .ibd data file. InnoDB tables support a maximum of 64TB;

The MyISAM table corresponds to three files, a .frm table structure file, a MYD table data file, and a .MYI index file. Starting with MySQL 5.0, the default limit is 256TB.

The difference between Redo Log and Binlog

Redo Log is a function of the InnoDB engine, while Binlog is a built-in function of MySQL Server and is recorded in binary files.

Redo Log is a physical log, which records the update status content of the data page. Binlog is a logical log, which records the update process.

Redo Log is written in a circular manner, the log space size is fixed, Binlog is written additionally, after one is written, the next one is written, and it will not be overwritten.

Redo Log can be used for automatic recovery of transaction data after the server is down abnormally, and Binlog can be used for master-slave replication and data recovery. Binlog does not have automatic crash-safe capabilities.

In the application, multiple indexes can be added to the slave database to optimize queries. These indexes in the main database can be omitted to improve writing efficiency.

Reading and writing separation scheme

1Read immediately after writing

After writing to the database, the read operation will be completed within a certain period of time Go to the main library, and then read operations access the slave library.

2 Secondary Query

First go to the slave database to read the data. If it cannot be found, go to the main database to read the data. This operation will easily return the read pressure to the main library. In order to avoid malicious attacks, it is recommended to encapsulate the database access API operations, which is beneficial to security and low coupling.

3According to special business processing

Adjust according to business characteristics and importance. For example, important business data reading and writing with high real-time requirements can be placed in the main database. For secondary businesses that do not require high real-time performance, reading and writing can be separated, and queries can be made from the database.

Related recommendations: "mysql tutorial"

The above is the detailed content of Detailed introduction to mysql theory and basic knowledge. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

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.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

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".

How to create navicat premium How to create navicat premium Apr 09, 2025 am 07:09 AM

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

How to create a new connection to mysql in navicat How to create a new connection to mysql in navicat Apr 09, 2025 am 07:21 AM

You can create a new MySQL connection in Navicat by following the steps: Open the application and select New Connection (Ctrl N). Select "MySQL" as the connection type. Enter the hostname/IP address, port, username, and password. (Optional) Configure advanced options. Save the connection and enter the connection name.

MySQL and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 10, 2025 am 09:30 AM

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.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

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.

How to recover data after SQL deletes rows How to recover data after SQL deletes rows Apr 09, 2025 pm 12:21 PM

Recovering deleted rows directly from the database is usually impossible unless there is a backup or transaction rollback mechanism. Key point: Transaction rollback: Execute ROLLBACK before the transaction is committed to recover data. Backup: Regular backup of the database can be used to quickly restore data. Database snapshot: You can create a read-only copy of the database and restore the data after the data is deleted accidentally. Use DELETE statement with caution: Check the conditions carefully to avoid accidentally deleting data. Use the WHERE clause: explicitly specify the data to be deleted. Use the test environment: Test before performing a DELETE operation.

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

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.

See all articles