<p>I like InnoDB's safety, consistency, and self-checking.</p>

<p>But I need MyISAM's speed and light weight.</p>

<p>How can I make MyISAM less prone to corruption due to crashes, bad data, etc.? It takes forever to go through a check (either CHECK TABLE or myisamchk). </p>

<p>I'm not asking for transactional security -- that's what InnoDB is for. But I do want a database I can restart quickly rather than hours (or days!) later.</p>

<p><em>UPDATE:</em> I'm not asking how to load data into tables faster. I've beat my head against that already, and determined that using the MyISAM tables for my LOAD DATA is simply much faster. What I'm after now is <em>mitigating the risks</em> of using MyISAM tables. That is, reducing chances of damage, increasing speed of recovery.</p>

[{'answer_id': 75892, 'author': 'Tim Howland', 'author_id': 4276, 'author_profile': 'https://Stackoverflow.com/users/4276', 'pm_score': 0, 'selected': False, 'text': '<p>Are you married to MySQL? <a href="http://www.postgresql.org/" rel="nofollow noreferrer">Postgres</a> is ACID-compliant (like innoDB) and (when well-tuned) nearly as speedy as MyISAM.</p>\n'}, {'answer_id': 75961, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 2, 'selected': False, 'text': '<p>MyISAM\'s supposed speed benefits can actually go away pretty quickly - the fact that it lacks row-level locking means small updates can cause large amounts of data to be locked, and queries to block.  Because of that, I\'m skeptical of claimed MyISAM speed benefits: start doing several UPDATEs, and the queries per second will tank.</p>\n\n<p>I think you\'re better off asking "How can applications backed with InnoDB be made faster?" and the answer then deals with caching data, perhaps at the object level, in lightweight caches - there is a cost for ACID, and for, say, web applications, it\'s not really needed.</p>\n\n<p>If UPDATEs are rare (if they aren\'t, MyISAM isn\'t a good choice) then you can even use the MySQL query cache.</p>\n\n<p>memcached (<a href="http://www.danga.com/memcached/" rel="nofollow noreferrer">http://www.danga.com/memcached/</a>) is a very popular option for object caching.  Depending on your application you have other options as well (HTTP caches, etc.)</p>\n'}, {'answer_id': 76789, 'author': 'MarkR', 'author_id': 13724, 'author_profile': 'https://Stackoverflow.com/users/13724', 'pm_score': 1, 'selected': False, 'text': '<p>The performance advantages of MyISAM are actually pretty minimal in some cases; you need to benchmark your own application MyISAM vs InnoDB. Using the InnoDB transactional engine exclusively gives other benefits too.</p>\n\n<p>In my testing InnoDB will use up typically about 150% more disc space than MyISAM- this is because of its block structure and lack of index compression.</p>\n\n<p>If you can afford it, just use InnoDB instead.</p>\n\n<p>As far as answering your actual question goes: If you partition your table into multiple MyISAM tables, the amount of repair needed in a crash will be much less; if your data are large, this might be a good idea anyway for other reasons.</p>\n'}, {'answer_id': 82693, 'author': 'Tim Howland', 'author_id': 4276, 'author_profile': 'https://Stackoverflow.com/users/4276', 'pm_score': 0, 'selected': False, 'text': "<p>Your comment:</p>\n\n<blockquote>\n  <p>No, the major problem is the amazingly\n  disk-intensive initial import of data\n  into the table. MyISAM time: 12\n  minutes. InnoDB time: 3+ hrs. After my\n  initial load, UPDATEs are non-existent\n  and INSERTs are rare. No known\n  solution to InnoDB's disappointing\n  load operation.</p>\n</blockquote>\n\n<p>suggests dropping constraints and indexes, then enabling / rebuilding them after the load may significantly speed it up- I assume you tried that? Did that improve things?</p>\n"}, {'answer_id': 82840, 'author': 'Marc Gear', 'author_id': 6563, 'author_profile': 'https://Stackoverflow.com/users/6563', 'pm_score': 0, 'selected': False, 'text': '<p>This really depends a lot on how your use of the tables.  If they are write heavy, then you may want to consider removing indexes, which will speed up the recovery time.  If they are read heavy, you may want to consider using replication which will serialise all writes to your tables, minimising the recovery time for your read copy after a crash.  </p>\n\n<p>Once thing you could do is write to an InnoDB copy of the table, and then replicate to a MyISAM copy.  The performance benefits of MyISAM are mostly read-oriented anyway.</p>\n\n<p>Using replication of course, you will have lag time between reads and writes</p>\n'}, {'answer_id': 94613, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 0, 'selected': False, 'text': "<p>Get a good UPS, with decent power conditioning.  Run on stable and redundant hardware.</p>\n\n<p>I don't trust MyISAM tables to ever survive a crash during a write, so I think your best bet is on reducing the occurrence of crashes (and writes).</p>\n"}, {'answer_id': 381826, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>in normal practice, you shouldn't get corruption. if you are getting corruption, you need to look at things like bad memory, bad hard drive, bad drive controller, or possibly a mysql bug.</p>\n\n<p>if you want to side-step all that, you could set up a replication slave. when the master dies, stop the replication on the slave and make it your new master. the clear the data off your old master and set it up as a slave. user down-time will be limited to the amount of time it takes to detect that the master died and bring the slave up.</p>\n\n<p>this has the added benefit of being a good way to achieve a zero-downtime backup: shut down the slave process and back up the slave.</p>\n"}, {'answer_id': 382755, 'author': 'Jonathan', 'author_id': 19272, 'author_profile': 'https://Stackoverflow.com/users/19272', 'pm_score': 1, 'selected': False, 'text': '<p>While I agree with the innodb comments, I will give a solution to your MyISAM problem.</p>\n\n<p>A good way to prevent corruption and increasing speed would be to use <a href="http://dev.mysql.com/doc/refman/5.1/en/merge-storage-engine.html" rel="nofollow noreferrer">MERGE tables</a></p>\n\n<p>You can use 2 or more MyISAM files. One is usually for backup\'d old data that isn\'t used that often and the other is newer data. Then you will have 2 FRM (the MyISAM table files) on your harddisk and one will be protected. Usually you <a href="http://dev.mysql.com/doc/refman/5.1/en/myisampack.html" rel="nofollow noreferrer">compress</a> the old MyISAM tables and then they will defiantly not be corrupted, since they become read-only.</p>\n\n<p>This technique is usually used to speed up big MyISAM tables, but you can apply it here as well.</p>\n\n<p>Hope that helped your question. While I realize it didn\'t really help crash-proof MyISAM, it does give quite a bit of protection.</p>\n'}]
['https://Stackoverflow.com/questions/75857', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12332/']