The storage engine is the main type of MySQL table
In MySQL, the most useful way to tell tables apart is by storage engine. The engine decides how rows are stored on disk, which kinds of indexes the table can use, how the table is locked when several sessions use it at once, and whether changes can be rolled back or recovered after a crash. Every ordinary table has one engine, and you choose it when you create the table.
For most tables, the right choice is InnoDB, which has been the default since MySQL 5.5. The other engines cover narrower jobs, such as temporary lookup data, exchanging data with spreadsheets, or keeping write-once logs.
Two other things are sometimes mistaken for table types. A view stores a saved query rather than rows, so it has no storage engine of its own. A temporary table lasts only as long as the session that created it, and it is covered further down.
The storage engines MySQL supports
The MySQL 8.4 documentation lists the engines below. Which ones you can use depends on your MySQL edition and build, so run SHOW ENGINES; to see what your server supports.
| Engine | Typical use | Key point |
|---|---|---|
| InnoDB | Most application tables | The default; supports transactions and foreign keys |
| MyISAM | Older or read-mostly tables | Table-level locks; no transactions or foreign keys |
| MEMORY | Temporary lookup data kept in RAM | Data is lost when the server restarts |
| CSV | Exchanging data with spreadsheets and scripts | No indexes; every column must be NOT NULL |
| ARCHIVE | Write-once logs and history | Insert and read only; compressed |
| BLACKHOLE | Replication setups | Accepts writes but discards them |
| MERGE | Treating identical MyISAM tables as one | Built on MyISAM tables |
| FEDERATED | Querying tables on another MySQL server | Depends on the remote server |
| NDB | High-availability setups | Only in builds that include it |
| EXAMPLE | Developers writing a new engine | Stores no data |
InnoDB: the default for most tables
InnoDB is the engine to start with. It is transaction-safe in the ACID sense: a group of statements can be committed together or rolled back, and committed data survives a crash. It uses row-level locking, so a change locks the rows it touches rather than the whole table. Readers generally do not wait for writers, which helps when many sessions are active.
InnoDB also enforces foreign key constraints, which keep related rows consistent across tables. Only InnoDB supports foreign keys, so both tables in a relationship need to use it. The primary key index also holds the row data, which makes lookups by primary key efficient. In current versions, each InnoDB table gets its own .ibd file by default.
InnoDB’s default isolation level is REPEATABLE READ, which prevents dirty reads: reading data that another transaction has changed but not yet committed. For the background on that term, see “What is dirty read in DBMS?”
MyISAM and where it still appears
MyISAM is an older engine. It is no longer the default, so you have to ask for it by name, as in CREATE TABLE t (i INT) ENGINE = MYISAM;. Its main trade-offs are:
- Locking. Locks are held at the table level. A write to a table makes other sessions wait until it finishes.
- No transactions. A change cannot be rolled back, and MyISAM has no foreign keys.
- Files. Data goes in a
.MYDfile and indexes in a.MYIfile. In current versions, the table definition is kept in the data dictionary rather than in a.frmfile. - Crash recovery. After an unexpected shutdown, a MyISAM table may need checking or repair with
REPAIR TABLEor themyisamchktool.
Most new work uses InnoDB instead. You will still find MyISAM in older applications and in some read-mostly setups. Two migration points are worth knowing. Partitioned MyISAM tables created in older versions cannot be used in MySQL 8.4, and compressed MyISAM tables made with myisampack are read-only.
MariaDB, the fork of MySQL, includes Aria, a crash-safe engine based on MyISAM. If you are weighing the two servers, the question “Which is better, MySQL or MariaDB?” is covered separately.
MEMORY, CSV and ARCHIVE
MEMORY
The MEMORY engine, formerly called HEAP, keeps table data in RAM and creates no data files. Its table definition is stored, so the table still exists after a restart, but it comes back empty. It suits data you can rebuild, such as a short-lived lookup table. Three limits matter:
- Size. The table is capped by
max_heap_table_size, which defaults to 16MB. - Locking. Locks are held at the table level, so heavy updates from several sessions can slow each other down.
- Column types. BLOB and TEXT columns are not allowed. VARCHAR is allowed, but it is stored at a fixed length. Check the different data types of sql before you pick column types for a MEMORY table.
Indexes can use either HASH, the default, or BTREE. You choose the type with a USING clause.
CSV
The CSV engine stores each row as a line of comma-separated text in a .CSV file. A .CSM file holds the table state and row count. Because the data is plain text, spreadsheet programs can open it. The limits are real: CSV tables have no indexes, every column must be declared NOT NULL, and the engine does not support transactions or partitioning. Use it to hand data to scripts or spreadsheets, not as the main store for an application.
ARCHIVE
The ARCHIVE engine compresses rows as they are inserted, which suits logs and historical records that you rarely change. It supports INSERT and SELECT, but not UPDATE or DELETE. The only index it allows is one on an AUTO_INCREMENT column, and every SELECT reads the whole table.
CREATE TABLE app_log (
id INT AUTO_INCREMENT PRIMARY KEY,
msg TEXT
) ENGINE = ARCHIVE;
Engines for special setups
- BLACKHOLE accepts writes and throws them away, so queries return no rows. It is used in some replication setups.
- MERGE presents a set of identical MyISAM tables as a single table.
- FEDERATED lets a query reach tables that live on a separate MySQL server.
- NDB is a distributed engine aimed at high availability. It is available only in MySQL builds that include it.
- EXAMPLE is a stub that shows developers how to write an engine. It can create tables, but it stores no data.
Temporary tables are a separate kind of table
A temporary table is created with CREATE TEMPORARY TABLE. Only the session that created it can see it, and MySQL drops it when that session ends. A temporary table can share a name with a permanent table, and inside that session it hides the permanent one, so use distinct names to avoid confusion. MySQL also creates internal temporary tables while it runs some queries, but you do not create or manage those yourself.
Checking which engine a table uses
In the mysql command-line client, this shows one table’s engine in the Engine field of the output:
SHOW TABLE STATUS LIKE 'orders'\G
To list the engine for every table in a database:
SELECT TABLE_NAME, ENGINE
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'shop';
To see the engine that new tables get by default, run SELECT @@default_storage_engine;. To see which engines your server supports, run SHOW ENGINES;. In its output, the Support column shows YES, NO, or DEFAULT.
Changing a table’s engine
Use ALTER TABLE to change an existing table’s engine:
ALTER TABLE orders ENGINE = InnoDB;
This rebuilds the table and copies its data. On a large table it can take a long time and needs free disk space while it runs. Before you change engines, check a few things:
- If the table takes part in foreign keys, both sides must use InnoDB.
- Changes made to a MyISAM table inside a transaction cannot be rolled back.
- Mixing engines within one database is allowed, but the engine you pick for each table affects what that table can do.
- Test the change on a copy of the data first.
Choosing an engine
Start with InnoDB unless you have a specific reason not to. Pick another engine only when its limits fit your need:
- Use MEMORY only for data you can rebuild, and only when it fits within its size limit.
- Use ARCHIVE for logs and history that you rarely change.
- Use CSV to hand data to scripts or spreadsheets.
- Use MyISAM only when an existing application requires it, and consider moving that table to InnoDB when you can.
Whatever you choose, check the result against your own workload before you switch. The engine you pick matters less than whether your tables, indexes and queries suit the way the data is used.