If you are looking to improve the performance of MySQL databases in your software, you may need to know all the differences between InnoDB and MyISAM, two well-known types of MySQL storage engines. And if you’re about to choose one of them, we think you’d like to know what each of them has to offer and which one will best suit your software. That’s what our article is going to help you with.
CONTENTS1. What is the MyISAM engine?2. What is the InnoDB engine?3. The main differences between MyISAM and InnoDB4. MyISAM vs InnoDB: a detailed comparison5. How to check if you are using MyISAM or InnoDB6. When it is best to use MyISAM and when to use InnoDB7. How to convert MyISAM to InnoDB (and vice versa)8. Conclusion
What is the
In the past, MyISAM was considered the best, fast and well-optimized option for heavy read operations. It was used for many different things, from performing data analysis to developing simple content management systems for forums or building smaller search engines. Some developers created tools and solutions that were adapted to MyISAM, as it was thought to be simpler than InnoDB. Actually, many developers started their journey into the MySQL world with the use of MyISAM. However, in 2009 it was replaced by InnoDB as the default MySQL storage engine. Still, it offers many useful extensions for MySQL developers.
What is the
InnoDB engine? The
InnoDB general-purpose storage engine for MySQL has evolved from a storage subsystem to a full-fledged storage engine. It was the default MySQL engine from version 5.6 onwards, thanks to its combination of high performance and reliability. It can be easily integrated into the software. While MySQL determines how data is stored in a database, the InnoDB storage engine stores the data on disk or keeps it in main memory for quick access. When a transaction is completed, the data is written to the storage medium according to the transaction. It is important to note that incomplete changes are not stored in the database.
The main differences between
MyISAM and InnoDB
In general, MyISAM is an older and less efficient storage engine than InnoDB. The most common differences between these two engines are as follows: InnoDB is more stable, faster, and easier to configure; It also supports transactions. It’s the default storage engine of choice for a reason, and you can use InnoDB features without needing to worry about compatibility issues. If you need to store large amounts of data or ensure that transactions will work correctly, choose InnoDB.
The MyISAM engine is not very good at storing large amounts of data as it stores everything in a single table. When you need to add data to the database, you need to lock the entire table, which can cause your database to stop working until it is unlocked. In the InnoDB engine, each row is stored separately in a separate table. This means that when you insert data into a MySQL database, you don’t need to lock all rows.
Now let’s proceed to a more detailed description of these storage engines.
InnoDB: A Detailed Comparison
Now let’s do a head-to-head comparison of the MyISAM and InnoDB storage engine. The former stores data in its memory, while the latter uses disk space for storage. Both are considered fast, but one is better than the other, depending on the situation you’re dealing with. For example, MyISAM is faster when inserting, updating, or deleting large amounts of data, because the database does not have to use disk space. However, InnoDB is more efficient at indexing and retrieving information, and is generally a much more advanced and preferred option.
1. Storage Engine Type
Let’s start with MySQL engine types. InnoDB is a transactional storage engine, while MyISAM belongs to the non-transactional category. The first means that, if the manipulation of your data involved a transaction, a rollback will be automatically triggered in case the transaction is not completed. This is obviously recommended over MyISAM, which does not support transactions, and with which, if necessary, you will have to revert the changes manually.
InnoDB is a storage engine for online transaction processing. It stores the actual data in a separate area called the InnoDB buffer pool. This area allows MySQL databases to locate and access data efficiently and quickly. The InnoDB engine is key to the stability and performance of a MySQL database. Unlike it, the MyISAM engine is an older and less popular storage engine for storing tables.
. ACID properties
Atomicity, consistency, insulation and durability are the well-known ACID properties. In the event of a system error or failure, compliance with these properties ensures that the transaction will be completed. And while InnoDB offers full compliance, MyISAM does not.
4. Performance comparison
InnoDB supports transactional properties. It offers faster code writing speed with rollbacks and commits. InnoDB performs with large volumes of data is better than MyISAM. Meanwhile, MyISAM is faster to read, does not support transactional properties, and its performance with large volumes of data leaves much to be desired compared to InnoDB.
. Foreign Key Support
A foreign key in one table is a set of attributes that references the primary key in another table. A table can have multiple foreign keys, and each foreign key can have a different parent table. With MyISAM, you cannot add foreign key restrictions, whereas InnoDB fully supports this feature.
6. Table-level locking
When the locking option is enabled, two or more users cannot modify the same data simultaneously. This feature preserves the validity of the data. Table locking is the default locking method for MyISAM, which allows you to modify tables in a single session. The tables are locked in a certain order. The table locking method can be used for read-only databases that do not require much memory.
For InnoDB, the default locking method is row-level locking. Rows are locked to support multiple sessions in the selected rows. It is highly preferable for databases that require more than one active user.
Bottom line: InnoDB offers flexible row-level locks, while MyISAM can only do table-level locks. Failure recovery in InnoDB is also superior.
7. Caching and indexing
Now a few words about caching and indexing in InnoDB and MyISAM. In InnoDB, there is a large pool of buffers that can be used to store data and indexes. As for MyISAM, there is a key buffer that is used for indexes. Meanwhile, the main caching mechanism is a cache key, which uses MYI files to cache pages.
How to check if you are using MyISAM or InnoDB
If you don’t know which storage engine is currently being used in your MySQL database, let’s check it out and see. The first way is to start MySQL Shell and run SHOW DATABASES; , and then locate and select the required database with the USE database_name; send.
After that, a confirmation message will be displayed that the database is located. You can now use the SHOW CREATE TABLE command to display table and storage engine information. It looks like this:
SHOW CREATE TABLE database_name.table_name;
The output will display the default storage engine for the required table
There is an easier way to do this if you are using dbForge Studio for MySQL. In Database Explorer, simply right-click the required table and click Properties on the shortcut menu. As you can see, we have “INNODB” in the Engine field of the Properties window in the lower left corner of the screen.
When is it best to use MyISAM
and when to use InnoDB
If a MyISAM table has a problem, it will only affect the table. If there is a problem with other tables or databases, it will not affect the operations of other tables or databases. Therefore, MyISAM can be recommended for servers with multiple sites.
The InnoDB storage engine is recommended for common table operations. It has better performance, better functionality, and can also substantially reduce memory usage on the server. Naturally, it is generally preferred over MyISAM. Still, it’s worth noting that because issues with InnoDB tables can cause data loss on other InnoDB tables, it’s important to make sure you’ve enabled automatic backups.
How to convert MyISAM to InnoDB (and vice versa) Converting MyISAM to InnoDB can be
quite useful if, for example, you find an older MyISAM table that needs to be converted to match your current InnoDB environment.
How to convert all tables from
MyISAM to InnoDB
If you want to
convert all tables
a necessary database, you can do it safely via phpMyAdmin
1. Once you start it and select the required database, you can run the following query on it, having replaced database_name with the actual name of your database using SQL concatenation: SELECT
CONCAT(‘ALTER TABLE ‘,TABLE_NAME,’
ENGINE=InnoDB;’) OF INFORMATION_SCHEMA. TABLES WHERE ENGINE=’MyISAM’ AND table_schema=’database_name’;
For example, this is what it will look like with the sakila database:
2. After you submit this query, you will see the list of all tables that will be converted to InnoDB.
3. Click +Options above the results, select Full Texts, and click Go in the lower-right corner of the screen.
4. Select the Show All check box, and copy all queries using Copy to clipboard in the Query Results Operations box.
5. Paste the results into the text editor and copy all lines starting with ALTER TABLE to your clipboard.
6. Click the SQL tab above the results and paste the ALTER TABLE statements into the text field, then click Go once again. All tables in the database will be converted to InnoDB.
How to convert a single MyISAM table to InnoDB
If you want to convert a single table from MyISAM to InnoDB, run the ALTER TABLE command, after you have replaced database_name and table_name with the actual database and table names: ALTER TABLE database_name.table
You can also do this using the dbForge Studio for MySQL mentioned above:
How to convert InnoDB to MyISAM Similarly, you may want to convert an
InnoDB table to MyISAM.
The method is the same as in the previous case:
ALTER TABLE database_name.table_name ENGINE=MyISAM;
Note that your InnoDB table may have foreign key restrictions, which are not supported by MyISAM. If you try to convert a table with such constraints, you will encounter an error.
We hope this article has helped you better understand the most crucial differences between these two MySQL storage engines and finally allowed you to make the optimal decision based on your needs and requirements
And if you’re looking for an all-encompassing MySQL IDE that works with different storage engines, you can also try dbForge Studio for MySQL. It allows you to easily create and execute queries, develop and debug stored routines, automate database object management, compare and synchronize MySQL databases, analyze table data, and much more. Its rich functionality is delivered under a sleek and intuitive user interface.