SoFunction
Updated on 2025-04-12

Common storage engines and differences in MySQL

Common storage engines and differences in MySQL

MySQL supports multiple storage engines, and there are significant differences in transactions, lock mechanisms, performance, storage methods, etc. between different engines.

Here are common storage engines and their differences:

1. InnoDB

Features

  • Transaction support: Supports ACID transactions to ensure data consistency.
  • Row-level lock: Row-level lock is used by default to improve concurrency performance.
  • Foreign key constraints: Support foreign keys to ensure data integrity.
  • Crash recovery:passredo logAchieve rapid recovery after a crash.
  • Clustered Index: Data is stored in primary key order (primary key query efficiency is high).
  • Support MVCC: Multi-version concurrent control to reduce read and write conflicts.

Applicable scenarios: Systems that require transactions, high concurrent writes (such as payment systems, order systems), and complex queries.

2. MyISAM

Features

  • Table-level lock: Read and write operations lock the entire table, and the concurrency performance is low.
  • No transaction supported: Data consistency cannot be guaranteed (such as write interrupts may cause data corruption).
  • Nonclustered index: Indexes are stored separately from data (.MYDData File +.MYIindex file).
  • Full text index: Full-text search is supported (but InnoDB also supports it in MySQL 5.6+).
  • Compression table: Supports read-only compressed tables, saving storage space.

Applicable scenarios: Scenarios where more reads and fewer writes and do not require transactions (such as logging systems, data warehouses).

3. MEMORY

Features

  • Memory storage: The data is stored in memory and has a fast read and write speed.
  • Table-level lock: Concurrency performance is limited.
  • No persistence supported: Data is lost after service restart.
  • Hash index: The hash index is used by default (suitable for equivalent queries).

Applicable scenarios: Temporary tables, caches, or fast access to non-critical data.

4. Archive

Features

  • High compression rate: Data compression storage, saving disk space.
  • Only insertion and query: Update or delete operations are not supported.
  • Row-level lock: Lock the current row when inserted.

Applicable scenarios: Archive storage (such as historical logs, audit records).

5. CSV

Features

  • Text file storage: The data is stored in CSV format and can be viewed directly in a text editor.
  • Indexing is not supported: Inefficient query.
  • No transaction supported

Applicable scenarios: Data import/export, exchange data with other systems.

6. Blackhole

Features

  • No data stored: The written data is discarded, but the binlog will be recorded.
  • Used for data transfer: Write operations can be forwarded to other databases.

Applicable scenarios: Relay of data replication or logging.

Core difference comparison

characteristic InnoDB MyISAM MEMORY Archive
Transaction support ✔️
Locking mechanism Row-level lock Table-level lock Table-level lock Row-level lock (insert only)
Foreign key constraints ✔️
Crash recovery ✔️(redo log) ❌ (Vulnerable to damage)
Index Type B+Tree (clustered index) B+ Tree (non-aggregated) Hash/B+ Tree No index
Storage limits 64TB 256TB Memory limit none
Compression capability ✔️ (Table Compression) ✔️ (read-only compression) ✔️ (High compression rate)

How to choose a storage engine?

  1. Need transaction or high concurrent writeInnoDB
  2. Read more and write less and have no transaction requirementsMyISAM(But it has gradually been replaced by InnoDB).
  3. Temporary data or cacheMEMORY
  4. Archive storageArchive
  5. Data exchange or loggingCSV/Blackhole

Summarize

MySQL uses InnoDB by default, due to its transaction support and high concurrency capabilities, while other engines are suitable for specific scenarios (such as archiving, memory tables, etc.). When choosing, you need to weigh transactions, performance, storage costs and other factors based on business needs.

The above is personal experience. I hope you can give you a reference and I hope you can support me more.