[MySQL] MySQL storage engine
When creating a table, you can specify the type of the table, which is the storage engine of the table. The storage engine of a table determines how data is stored and accessed, as well as how transactions are stored. The storage engine of a table greatly affects the storage space and speed required to process SQL statements. Different storage engines have different characteristics. Some storage engines are very suitable for processing many complex SELECT statements, while others are more suitable for achieving fast updates.
InnoDB
InnoDB is MySQL’s default transactional engine and the most important and widely used storage engine. It is designed to handle a large number of short-lived transactions. Short-lived transactions are submitted normally in most cases and are rarely rolled back. InnoDB's performance and automatic crash recovery features make it popular for non-transactional storage needs.
Unless there are very special reasons to use other storage engines, the InnoDB engine should be given priority. ————"High-Performance MySQL"
InnoDB uses MVCC to support high concurrency and implements four standard isolation levels. Its default level is REPEATABLE READ, and the gap lock strategy prevents phantom reads.
InnoDB indicates that
built based on a clustered index supports foreign key constraints.
Supports automatic addition of column AUTO_INCREMENT attribute.
Affairs. The InnoDB storage engine is a standard MySQL storage engine that supports transactions.
There is no need to copy the entire table data when deleting or adding an index.
InnoDB has made many internal optimizations, including predictable read-ahead when reading data from disk, and an adaptive hash index that can automatically create a hash index in memory to accelerate operations. , and an insert buffer that speeds up insert operations.
InnoDB tables are built based on clustered indexes. The index structure of InnoDB is very different from other MySQL engines. Clustered indexes have high performance for primary key queries. However, the secondary index must contain the primary key column, so if the primary key column is large, all other indexes will be large. Therefore, if there are many indexes on the table, the primary key should be as small as possible.
MyISAM
MyISAM provides a large number of features, including full-text indexing, compression, spatial functions (GIS), etc., but MyISAM does not support transactions and row-level locks, and there is no doubt that The disadvantage is that it cannot be safely restored after a crash. In MySQL 5.1 and previous versions, MyISAM is the default storage engine. It is precisely because of this engine that even though MySQL has supported transactions for a long time, many people still think that MySQL is a non-transactional database.
MyISAM locks the entire table, not the rows.
Supports full-text indexing.
Supports compressed tables. Compressed tables cannot be modified and can greatly reduce disk space usage, thus reducing disk I/O operations and thereby improving query performance.
Storage
MyISAM will store the table in two files: the data file and the index file, with .MYD and .MYI extensions respectively. MyISAM tables can contain dynamic or static rows. MySQL will decide which row format to use based on the table definition.
In MySQL5.0, if the MyISAM table has variable-length rows, the default configuration can only handle 256TB of data
Features
As one of the earliest storage engines of MySQL, there are still some features.
Locking and Concurrency – Table Lock
MyISAM locks the entire table, not the rows. When reading, shared locks will be added to all tables that need to be read, and exclusive locks will be added to the tables when writing. However, while the table has read queries, new records can also be inserted into the table (concurrent insertion).
Repair
For MyISAM tables, MySQL can perform inspection and maintenance operations manually or automatically, but the repair mentioned here is a different concept from transaction recovery and crash recovery.
Index Features
For MyISAM tables, even long fields such as BLOB and TEXT can create indexes based on their first 500 characters. MyISAM also supports full-text indexing, which is an index created based on word segmentation and can support complex queries.
Delayed update of index keys
When creating a MyISAM table, if the DELAY_KEY_WRITE option is specified, the modified index data will not be written to the disk immediately when each modification is completed.
MyISAM performance
The MyISAM engine is designed to be simple and the data is stored in a compact format, so the performance in certain scenarios is very good. However, the existence of table locks has a great impact on performance.
Archive engine
Archive storage engine only supports INSERT and SELECT. The Archive engine caches all writes and uses zlib to compress inserts, so it requires less disk I/O than MyISAM tables. But every SELECT query needs to perform a full table scan. Therefore, Archive tables are suitable for log and data collection applications, which often require full table scans for data analysis.
The Archive engine supports row-level locks and dedicated buffers, so high-concurrency insertions can be achieved. Archive will prevent other SELECTs from executing until all rows that exist in the table are returned before a query is started to achieve consistent reads. In addition, batch inserts are also implemented that are invisible to read operations until they are completed. This mechanism mimics some features of transactions and MVCC, but the Archive engine is not a transactional engine, but an engine optimized for high-speed insertion and compression.
CSV Storage Engine
This engine can process ordinary CSV files as MySQL tables, but this table does not support indexes. You only need to copy the CSV file to the data directory of the CSV storage engine, and it can be opened and used using the rules listed in MySQL.
Memory Engine
If you need to access data quickly, and the data will not be modified or lost after restarting, then using the Memory table is very useful. Memory tables are an order of magnitude faster than MyISAM tables because all data is stored in memory and no disk I/O operations are required. The structure of the Memory table will be retained after restarting, but the data will be lost.
Supports Hash index, so the search operation is very fast.
is a table-level lock, so concurrent write performance is low.
does not support BLOB or TEXT type columns, and the length of each row is fixed. Even if varchar is specified, it will be converted to char in actual storage.
Explanation
Unless you need to use some features that InnoDB does not have, and there is no other way to replace it, you should give priority to the InnoDB engine—— "High-Performance MySQL"
In addition, the above only lists some commonly encountered storage engines, which is not comprehensive.
When creating a table, you can specify the type of the table, which is the storage engine of the table. The storage engine of a table determines how data is stored and accessed, as well as how transactions are stored. The storage engine of a table greatly affects the storage space and speed required to process SQL statements. Different storage engines have different characteristics. Some storage engines are very suitable for processing many complex SELECT statements, while others are more suitable for achieving fast updates.
InnoDB
InnoDB is MySQL’s default transactional engine and the most important and widely used storage engine. It is designed to handle a large number of short-lived transactions. Short-lived transactions are submitted normally in most cases and are rarely rolled back. InnoDB's performance and automatic crash recovery features make it popular for non-transactional storage needs.
Unless there are very special reasons to use other storage engines, the InnoDB engine should be given priority. ————"High-Performance MySQL"
InnoDB uses MVCC to support high concurrency and implements four standard isolation levels. Its default level is REPEATABLE READ (repeatable read), and the gap lock strategy prevents phantom reads.
InnoDB indicates that
built based on a clustered index supports foreign key constraints.
Supports automatic addition of column AUTO_INCREMENT attribute.
Affairs. The InnoDB storage engine is a standard MySQL storage engine that supports transactions.
There is no need to copy the entire table data when deleting or adding an index.
InnoDB has made many internal optimizations, including predictable read-ahead when reading data from disk, and an adaptive hash index that can automatically create a hash index in memory to accelerate operations. , and an insert buffer that speeds up insert operations.
InnoDB tables are built based on clustered indexes. The index structure of InnoDB is very different from other MySQL engines. Clustered indexes have high performance for primary key queries. However, the secondary index must contain the primary key column, so if the primary key column is large, all other indexes will be large. Therefore, if there are many indexes on the table, the primary key should be as small as possible.
MyISAM
MyISAM provides a large number of features, including full-text indexing, compression, spatial functions (GIS), etc., but MyISAM does not support transactions and row-level locks, and there is no doubt that The drawback is that it cannot be safely restored after a crash. In MySQL 5.1 and previous versions, MyISAM is the default storage engine. It is precisely because of this engine that even though MySQL has supported transactions for a long time, many people still think that MySQL is a non-transactional database.
MyISAM locks the entire table, not the rows.
Supports full-text indexing.
Supports compressed tables. Compressed tables cannot be modified and can greatly reduce disk space usage, thus reducing disk I/O operations and thereby improving query performance.
Storage
MyISAM will store the table in two files: the data file and the index file, with .MYD and .MYI extensions respectively. MyISAM tables can contain dynamic or static rows. MySQL will decide which row format to use based on the table definition.
In MySQL5.0, if the MyISAM table has variable-length rows, the default configuration can only handle 256TB of data
Features
As one of the earliest storage engines of MySQL, there are still some features.
Locking and Concurrency – Table Lock
MyISAM locks the entire table, not the rows. When reading, shared locks will be added to all tables that need to be read, and exclusive locks will be added to the tables when writing. However, while the table has read queries, new records can also be inserted into the table (concurrent insertion).
Repair
For MyISAM tables, MySQL can perform inspection and maintenance operations manually or automatically, but the repair mentioned here is a different concept from transaction recovery and crash recovery.
Index Features
For MyISAM tables, even long fields such as BLOB and TEXT can create indexes based on their first 500 characters. MyISAM also supports full-text indexing, which is an index created based on word segmentation and can support complex queries.
Delayed update of index keys
When creating a MyISAM table, if the DELAY_KEY_WRITE option is specified, the modified index data will not be written to the disk immediately when each modification is completed.
MyISAM performance
The MyISAM engine is designed to be simple and the data is stored in a compact format, so the performance in certain scenarios is very good. However, the existence of table locks has a great impact on performance.
Archive engine
Archive storage engine only supports INSERT and SELECT. The Archive engine caches all writes and uses zlib to compress inserts, so it requires less disk I/O than MyISAM tables. But every SELECT query needs to perform a full table scan. Therefore, Archive tables are suitable for log and data collection applications, which often require full table scans for data analysis.
The Archive engine supports row-level locks and dedicated buffers, so high-concurrency insertions can be achieved. Archive will prevent other SELECTs from executing until all rows that exist in the table are returned before a query is started to achieve consistent reads. In addition, batch inserts are also implemented that are invisible to read operations until they are completed. This mechanism mimics some features of transactions and MVCC, but the Archive engine is not a transactional engine, but an engine optimized for high-speed insertion and compression.
CSV Storage Engine
This engine can process ordinary CSV files as MySQL tables, but this table does not support indexes. You only need to copy the CSV file to the data directory of the CSV storage engine, and it can be opened and used using the rules listed in MySQL.
Memory Engine
If you need to access data quickly, and the data will not be modified or lost after restarting, then using the Memory table is very useful. Memory tables are an order of magnitude faster than MyISAM tables because all data is stored in memory and no disk I/O operations are required. The structure of the Memory table will be retained after restarting, but the data will be lost.
Supports Hash index, so the search operation is very fast.
is a table-level lock, so concurrent write performance is low.
does not support BLOB or TEXT type columns, and the length of each row is fixed. Even if varchar is specified, it will be converted to char in actual storage.
Explanation
Unless you need to use some features that InnoDB does not have, and there is no other way to replace it, you should give priority to the InnoDB engine—— "High-Performance MySQL"
In addition, the above only lists some commonly encountered storage engines, which is not comprehensive.
The above is the content of [MySQL] MySQL storage engine. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.
