MySQL Corrupt Table – No Space left – Index File too big

corruptionhard driveMySQLsql

I noticed that one of my servers was running out of disk space, due to heavy MySQL usage.
I stopped everything using the database, freed up some space and restarted mysqld.

Now, I checked my table with CHECK TABLE table and it gave me this:

+-------------------+-------+----------+---------------------------------------------------------------+
| Table             | Op    | Msg_type | Msg_text                                                      |
+-------------------+-------+----------+---------------------------------------------------------------+
| db.table | check | warning  | Table is marked as crashed and last repair failed             |
| db.table | check | warning  | 1 client is using or hasn't closed the table properly         |
| db.table | check | warning  | Size of indexfile is: 8656211968      Should be: 1024         |
| db.table | check | error    | Size of datafile is: 3068555264         Should be: 3068558490 |
| db.table | check | error    | Corrupt                                                       |
+-------------------+-------+----------+---------------------------------------------------------------+

How can I fix that? Simply running "REPAIR TABLE" does not work, I tried that and it never finished (killed it after 18 hours).
How can I save the data?

Best Answer

Your table(s) have crashed. This happens with non-transactional databases such as MyISAM. Consider a move to InnoDB if you don't need fulltext search.

Anways - you have to repair it, there is no way around. Try the following in a shell to repair all your tables:

#myisamchk --force --fast --update-state /path/to/your/database/*.MYI