MySQL MyISAM Storage Engine (original) (raw)

Skip to content

Summary: in this tutorial, you will learn about MySQL MyISAM storage engine and its features.

Introduction to MySQL MyISAM storage engine

MyISAM is a storage engine based on a deprecated ISAM (Indexed Sequential Access Method) storage engine.

MyISAM is a lightweight, non-transactional engine with high performance. It is also easy to copy between systems and has a very small data footprint.

MyISAM was the default storage engine in MySQL until version 5.5 when MySQL changed it to InnoDB. MySQL has also incorporated the major features of MyISAM into InnoDB, rendering MyISAM somewhat obsolete.

To create a MyISAM table, you use the set the ENGINE clause of the CREATE TABLE statement to MyISAM:

CREATE TABLE table_name( ... ) ENGINE=MYISAM;Code language: SQL (Structured Query Language) (sql)

When creating a MyISAM table, the storage engine generates two files with the same name as the table, each having the following extensions:

The storage engine stores the table definition in the MySQL data dictionary.

MyISAM storage engine does not support transactions, foreign keys, and row locking. Also, the storage limit of a MyISAM table is 256TB.

MyISAM storage engine does support full-text search indexes, geospatial data type, and indexing.

Converting MyISAM to InnoDB

If you want to convert all of your tables from MyISAM to InnoDB, you can follow these steps:

First, list all MyISAM tables of a specific database:

SELECT table_name FROM information_schema.tables WHERE table_schema = 'database_name' AND engine = 'MyISAM';Code language: SQL (Structured Query Language) (sql)

Second, convert each table to InnoDB using the ALTER TABLE statement:

ALTER TABLE table_name ENGINE = InnoDB;Code language: SQL (Structured Query Language) (sql)

If you need to convert all MyISAM tables in a database to InnoDB, you can use the following stored procedure:

`` DELIMITER // CREATE PROCEDURE ConvertMyISAMToInnoDB(IN dbName VARCHAR(100)) BEGIN DECLARE done INT DEFAULT FALSE; DECLARE tableName VARCHAR(100); DECLARE cur CURSOR FOR SELECT table_name FROM information_schema.tables WHERE table_schema = dbName AND engine = 'MyISAM';

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN cur;

read_loop: LOOP FETCH cur INTO tableName; IF done THEN LEAVE read_loop; END IF;

SET @alterSql = CONCAT('ALTER TABLE `', dbName, '`.`', tableName, '` ENGINE=InnoDB;');
PREPARE stmt FROM @alterSql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

END LOOP;

CLOSE cur; END // DELIMITER ; ``Code language: SQL (Structured Query Language) (sql)

The stored procedure ConvertMyISAMToInnoDB accepts a database name (dbName) as a parameter and does the following

For example, to convert all MyISAM tables in the HR database to InnoDB tables, you call the stored procedure ConvertMyISAMToInnoDB like this:

CALL ConvertMyISAMToInnoDB('HR');Code language: JavaScript (javascript)

Summary

Was this tutorial helpful?