2008.06.14

Most people who use MySQL know that MyISAM and InnoDB are the two most-common database engines available with the popular open-source database provider. I would bet that most of those people don't even take the time to select a storage-engine and just accept the database default. Those of you who are left probably heard from a friend who saw something online that said one of the two is better than the other. Those of you who are left will still probably learn a thing or two here :)

Storage Engine

The storage-engine is what will store, handle, and retrieve information for a particular table. As hinted by the opening of this article, there is no be-all end-all solution to every or even most cases. Each has very specific pros and cons that by design can not be all-inclusive of each other.

phpMyAdmin - Storage Engine

This is a screenshot of some of the available storage engines given to you by phpMyAdmin when you create a new table.

 

MyISAM

Let's start with MyISAM since it is the default engine with MySQL. MyISAM is based on the older but proven ISAM code but has been extended to be fully-featured while retaining the reliability. Data in MyISAM tables is split between three different files on the disk. One for the table format, another for the data, and lastly a third for the indexes.

The maximum number of rows supported amounts to somewhere around ~4.295E+09 and can have up to 64 indexed fields per table. Both of these limits can be greatly increased by compiling a special version of MySQL.

Text/Blob fields are able to be fully-indexed which is of great importance to search functions.

Much more technical information can be found on MySQL's MyISAM Manual Page.

InnoDB

InnoDB is relatively newer so the scene than MyISAM is so people are still weary about its use in environments than run fine under MyISAM. InnoDB is transaction-safe meaning data-integrity is maintained throughout the entire query process. InnoDB also provides row-locking, as opposed to table-locking, meaning while one query is busy updating or inserting a row, another query can update a different row at the same time. These features increase multi-user concurrency and performance.

Another great feature InnoDB boasts is the ability to use foreign-key constraints. FK constraints allows developers to ensure that inserted data referencing another table remains valid. For example, if you had an authors table and a books table and you wanted to insert a new book while referencing the author. The author would have to exist in the authors table before inserting them in the books table because a foreign key was specified in the books table. At the same time you would not be able to delete an author from the authors table if they had any entries associated with them in the books table. More on this in a later article...

Because of its row-locking feature InnoDB is said to thrive in high load environments. Its CPU efficiency is probably not matched by any other disk-based relational database engine.

 

Comparison

MyISAM in most cases will be faster than InnoDB for run of the mill sort of work. Selecting, updating and inserting are all very speedy under normal circumstances. It is the default engine chosen by the MySQL development team which speaks to its integrity, reliability, and performance.

InnoDB, or the OSX of the database-engine world, has emerged with some nifty features and created a niche for itself very quickly. Boasting features like row-level locking, transaction-safe queries, and relational table design are all very temping. The first two features really shine in a table that is constantly getting hammered like a logs, or search engine-type table. Since queries happen in the blink of an eye (faster actually) table-level locking(MyISAM) is sufficient in most other normal cases.

InnoDB recovers from a crash or other unexpected shutdown by replaying its logs. MyISAM must fully scan and repair or rebuild any indexes or possibly tables which had been updated but not fully flushed to disk.

Decision Matrix

Is your table is going to be inserted, deleted, and updated much much more than it is going to be selected?
InnoDB
If you need full-text search MyISAM
If you prefer/require relational database design InnoDB
Is disk-space or ram an issue? MyISAM
In Doubt? MyISAM

There is no winner.

REMEMBER! It's OK to mix table types in the same database! In fact it's recommended and frequently required. However, it is important to note that if you are having performance issues when joining the two types, try converting one to the other and see if that fixes it. This issue does not happen often but it has been reported.

 

Extra Reading

MySQL Performance Blog - Graphically shows how InnoDB overtakes MyISAM at a certain number of queries per second.

MySQL Manual InnoDB Overview - Great overview of capabilities and limitations.

MySQL Manual MyISAM Overview - Same as above

MySQL Manual Storage Engines - Information on the other less-used storage engines MySQL offers.

 

Please share on your success/horror stories with each engine and how you dealt with them. I would be very interested to hear about them.

 

Get my RSS Feed!

Comments

RusH-dmz on (6.14.2008 3:32 pm) says

I just converted all my tables to Innodb and setup the relations and haven't looked back. It really does make a huge difference as it keeps all your data together and warns you when you're first programming in some new features that you have made a mistake. I made some this morning that I wouldn't have caught for weeks without foreign keys!

 

John on (6.15.2008 5:16 pm) says

InnoDB's not 'new'

 

Mike Bernat on (6.16.2008 6:39 am) says

@John 

True, InnoDB is not brand-spanking new but..

ISAM, what MyISAM is based off of, was pre-1980s while InnoDB was integrated with MySQL in 2001. I could not find an exact date for the development of MyISAM but it is safe to say that it has been around longer.

 

Gibril on (8.27.2008 11:22 pm) says

what does INNO stands for in InnoDB

 

Kristiono Setyadi on (10.10.2008 2:36 am) says

I already using MyISAM for years, but as I need the transaction and MyISAM couldn't make it right, I want to move and looking forward to use InnoDB. Your article quite simple and it really helps me determine the future of my database application. But one problem I met, can you show me the example of "full-text search"?

Thank you very much :)

 

Rohan on (12.17.2008 10:32 pm) says

Your article played an important role in selecting the right engine for my database. Thanks a lot.

Rohan Mehta.

 

Eric on (1.31.2009 3:40 am) says

Nice Article, just what i needed. 
Im mixing up my tables now. 
InnoDB for integrity sensitive stuff!

 

elle on (2.25.2009 7:54 pm) says

i am newbie in programming, thanks for this informative article. actually i need to determine which engine should i used if i need to insert bulk of data to a table. e.g:scheduler run the code which read the content of text file, and insert it to table. 

 

Abhishek Ravi on (3.5.2009 1:35 pm) says

Excellent Article! Indeed could not made more simpler than that. Keep the good work going!

 

Linglom on (3.5.2009 9:33 pm) says

I'm going to use MySQL and still confuse about InnoDB and MyISAM. This article is very helpful. Thanks!

 

ardlian on (4.2.2009 11:42 pm) says

thx.. hat'a very use ful for me.. no i can look the differen betwen them... but could u tell me what the meaning of "full text search".

 

Web Developer on (4.17.2009 6:27 pm) says

Even though I have a lot more selects compared with insert/updates, I prefer InnoDB due to the foreign key constraints. But when I need full-text search for fields, I have to use MyISAM, and have built in foreign key checking into my application logic. 

 

panofish on (4.28.2009 3:08 pm) says

Good info... thanks

 

DJ Svadba on (7.15.2009 3:18 pm) says

Great article, thanks Mike.

 

aruljose on (7.21.2009 12:14 am) says

Would have been nice if the article and the comments are dated. Date is more important particulary for IT related info - will give a clear picture about how relevant the article is at a particular point of time.

 

Arjen on (9.2.2009 3:25 pm) says

I have a dedicated server, but InnoDB is not available in the list of engines. How can I enable/install it?

 

SHeRrY on (9.24.2009 4:11 am) says

Great Article! I like InnoDB's foreign key features, but I really need fast speed. So I think I will mix them up! Thanks!

 

Aleks on (10.9.2009 5:47 am) says

Your article is really useful, thanks Mike.

 

Neeraj Kumar on (11.16.2009 3:43 am) says

Good articles for choosing the mysql storage-engine between MyISAM and InnoDB.......

Thanks

 

Ruslanas on (11.18.2009 3:51 pm) says

It looks like database with InnoDB tables is much more robust if properly designed. I'd suggest using it for business applications which in many cases have less users and are critical to transaction safety.

 

JonB on (11.25.2009 8:05 pm) says

Thanks for a good explanation!  I have been struggling a bit on mixed table types. You have *turned on the light* just now.  Happy Thanksgiving Mike from a fellow Floridian.

 

Janine on (12.20.2009 7:58 pm) says

Additonally, please pay attention of the following:
If you're using MyISAM and you've plans to switch to InnoDB:
DO NOT CONVERT EXISTING MYISAM TABLES TO INNODB!!!
You must create new tables and choose directly InnoDB!

 

khurt on (1.21.2010 3:38 am) says

Janine, kindly explain please...

 

jehzlau on (1.25.2010 5:09 pm) says

this makes me want to convert MyISAM to InnoDB, specially in my super busy websites that requires a lot of inserting and updating queries. :D

 

sandeep on (1.27.2010 2:31 am) says

Thanks a lot for this article. It helped me to understand the basic diff. on MyISAM and InnoDB. :)

 

Martin on (2.11.2010 5:12 pm) says

Thx mate, this cleared things up a lot for me.
I was fighting to get my foreign keys working and since i'm new to mySQL I was at a loss why they didn't work the way they should.

Hats off to you sir.

 

Angga on (3.17.2010 11:13 am) says

thanks a lot Mike.
the article is very helpful.

 

Karthikeyan on (3.24.2010 2:50 am) says

Thanks a lot for helping me to understand the difference on MyISAM and InnoDB.

 

alnadabi on (4.10.2010 12:50 am) says

I was looking for compression for MyISAM and InnoDB on Dealing with very large table (+100 millions Records) 

I have very busy website, and currently I am using MyISAM for my Users Logs (Online) which have tens of Selecting/Inserting/Updating/Deleting queries is almost every second.

Currently I am facing long query process because of table locking, and I started of searching about alternatives of switching to another DB Engine 

Which one is faster on that side ??

Regards,
BMH

 

LailaSatria on (5.2.2010 8:54 pm) says

Noted the difference between InnoDB and MyISAM. Definitely I will choose InnoDB as I'm so familiar with RDMS. I would prefer to set relationship at the table level than at software/code level. I believe this can provide better database data integrity. 

 

lanclip.com on (5.4.2010 11:46 am) says

great thanks,
InnoDb and MyISAM is good type table but it is used belong of visitor on site. I vote MyISAM about process quickly. I vote InnoDB about activities stably.

 

jb.jigar on (7.20.2010 12:16 pm) says

Really, Good Work. Thanks
I was knowing this difference, but still I enjoyed this article.

 

Askar Ali Khan on (8.19.2010 1:02 am) says

Nice article..helps alot in understanding the difference between the two famous Engines in MySQL. In our case there are too many Insert and fewer SELECT, and we have a disk space issue so MyISAM right? 

Can someone tellme while insertion is in progress why the DB response get slow i mean the SELECT thing get too slow.

 

Gennady on (8.19.2010 5:14 pm) says

Askar,
You may want to read "Concurrency" and "Lock priorities" from "Using MyISAM in production" article:
www.mysqlperformanceblog.com/2006/06/17/using-myisam-in-production/

 

Web Development on (8.25.2010 10:14 am) says

To answer the above commenters' questions about what is better for a "Who's Online" table.  I would not go with either InnoDB or MyISAM, but instead with a Memory table. Temporary data like that is fine in a temporary in-memory table.

 

Insan on (9.6.2010 1:38 am) says

Thanks, it's a great article! I like the comparison. Does this affect the decision of whether to use composite or an auto-generated key as a primary key though?

 

Zeno on (10.3.2010 7:29 am) says

For those heavy insert/update tables (i.e. user action log tables), better use Innodb. And when doing archiving of those table (read only access), you can make them compressed MyISAM tables 

 

jayaram on (10.19.2010 9:00 am) says

thank you .. it's very useful information of decision making in table designing  

 

Michael R on (11.5.2010 9:40 am) says

Great Article! It's always nice to see some greater clarification on the different storage engines.

I look forward to more of your MySQL Articles!

 

Darren on (11.28.2010 12:22 pm) says

Nice article. I'm working with an authentication library that uses InnoDB and (like you said) all the other tables in my db I had created used (by default) MyISAM. You succinctly explained the differences. Thanks!

 

BitCom on (1.3.2011 4:50 pm) says

Many people claims that InnoDB is slower? Not in real life. Today, web applications are all about massive reads/writes. As we know, myisam locks down whole tables, which is actually slower. More reads/writes you do, slower it gets. InnoDB locks only the row in which it writes.

Logical explanation is, more traffic you get, more rows you have and less chance of hitting the same row. When you have high concurency of writes, you also need transactions to secure that writes.

 

Jason on (4.4.2011 8:38 pm) says

I have a table that contains ZIP code data (zip code, state name, state abbreviation, latitude coordinate, longitude coordinate).  This data will never be overwritten, deleted or updated.  If I get an update from the U.S. Postal Service, in that case I'll just replace the whole ZIP code table with a new table and new data.  The only thing that this table will be used for is SELECT statements, and then only for giving my Web site's users the ability to find information within the radius of X miles from a given ZIP code. I'll be using script programming to perform the necessary distance calculations. Given this, it seems to me that myISAM would be better for this purpose than innoDB.

But I have now learned that mySQL supports a database field type for storing geolocation data (called "Spatial Extensions"), and it lets you calculate distances between two points at the database level (rather than at the script programming level).  I'm wondering if innoDB would be the choice to use if I utilized those geolocation capabilities of mySQL.

 

Abbas Bashir on (5.17.2011 12:14 am) says

good info. really helpful for me 

 

Kiomarse on (6.22.2011 6:26 am) says

I use myIsam for a VERY BIG site (alexa rank of 4000)
I decided to change to innodb , 

result:VERY BAD
bcz: innodb needs a lot of memory 

so, if you can manage the TABLE LOCK of (update/insert) MYISAM, keep it.
I promise, TWICE! 

 

jean frederic nault on (6.23.2011 2:46 pm) says

The best is to have both of them with the sames (always synked by some load balancing process..) mysam for the selec and indb for all other stuff 

 

mike on (7.27.2011 3:23 am) says

it is very useful information of decision making in table designing  

 

som on (8.24.2011 5:57 am) says

Hi all

Is there any comparison between Myisam and Inndb Specifications.
e.g.-innodb_buffer_pool_size,read_buffer_size,read_rnd_buffer_size etc...

thanx in advance...

 

mrpitcouk on (9.16.2011 6:53 am) says

Simple and useful explaination. The last table is the Gem really nice

 

Arvind Bhardwaj on (9.30.2011 5:20 am) says

Excellent write up.
Thanks.

 

Cláudio Baptista / Rio de Jane on (11.24.2011 8:54 pm) says

Objective. You helped me!! Thanks!!! :)

 

בונה & on (11.28.2011 6:46 am) says

If I have table with a lot of reads, but ones a month I write to this table I should use MyISAM.
Am I right?

 

Weng Fu on (12.8.2011 6:47 pm) says

I confuse with isam or innodb. Not to use Inno if data is moving?

 

Kataskeyh istoselidon on (1.7.2012 6:39 am) says

Congratulations for the article, really great, just turned into InnoDB :)

 
* Name
* Email (Will not be displayed)
Website