15.1 Setting the Storage Engine

When you create a new table, you can specify which storage engine to use by adding an 'ENGINE' table option to the *note 'CREATE TABLE': create-table. statement:

 -- ENGINE=INNODB not needed unless you have set a different
 -- default storage engine.
 CREATE TABLE t1 (i INT) ENGINE = INNODB;
 -- Simple table definitions can be switched from one to another.
 CREATE TABLE t2 (i INT) ENGINE = CSV;
 CREATE TABLE t3 (i INT) ENGINE = MEMORY;

When you omit the 'ENGINE' option, the default storage engine is used. The default engine is *note 'InnoDB': innodb-storage-engine. in MySQL 5.7. You can specify the default engine by using the '--default-storage-engine' server startup option, or by setting the 'default-storage-engine' option in the 'my.cnf' configuration file.

You can set the default storage engine for the current session by setting the 'default_storage_engine' variable:

 SET default_storage_engine=NDBCLUSTER;

The storage engine for 'TEMPORARY' tables created with *note 'CREATE TEMPORARY TABLE': create-table. can be set separately from the engine for permanent tables by setting the 'default_tmp_storage_engine', either at startup or at runtime.

To convert a table from one storage engine to another, use an *note 'ALTER TABLE': alter-table. statement that indicates the new engine:

 ALTER TABLE t ENGINE = InnoDB;

See note create-table::, and note alter-table::.

If you try to use a storage engine that is not compiled in or that is compiled in but deactivated, MySQL instead creates a table using the default storage engine. For example, in a replication setup, perhaps your source server uses 'InnoDB' tables for maximum safety, but the replica servers use other storage engines for speed at the expense of durability or concurrency.

By default, a warning is generated whenever note 'CREATE TABLE': create-table. or note 'ALTER TABLE': alter-table. cannot use the default storage engine. To prevent confusing, unintended behavior if the desired engine is unavailable, enable the 'NO_ENGINE_SUBSTITUTION' SQL mode. If the desired engine is unavailable, this setting produces an error instead of a warning, and the table is not created or altered. See *note sql-mode::.

For new tables, MySQL always creates an '.frm' file to hold the table and column definitions. The table's index and data may be stored in one or more other files, depending on the storage engine. The server creates the '.frm' file above the storage engine level. Individual storage engines create any additional files required for the tables that they manage. If a table name contains special characters, the names for the table files contain encoded versions of those characters as described in *note identifier-mapping::.

 File: manual.info.tmp, Node: myisam-storage-engine, Next: memory-storage-engine, Prev: storage-engine-setting, Up: storage-engines