My old server was crashed but I was able to recover the databases from MySQL through testdrive.
I'm trying to dump a database using mysqldump
but it gives error for certain tables are crashed and should repaired.
I tried myisamchk --safe-recover /var/lib/mysql/database/table.MYI
And also myisamchk -r -q /var/lib/mysql/database/table.MYI
The tables fix themselves but unfortunately they delete that data from MYD
files.
Is there a way to fix the tables without losing data from MYD
or is it possible to convert the MYD
into human readable format like a txt file?
Best Answer
First of all, if your data is worth anything, don't store it in MyISAM.
I don't think you can reconstruct a table from corrupted MYD file. Records in MyISAM have different format that depends on values stored in each record. There are about 20 block types! To make it more fun the records in MyISAM can be fragmented. So, if you absolutely need the data from MyISAM table the only way I'm aware of is a C program with wildcard masks.
You can partially recover the table if you select from it ranges of the primary key. Corrupt PK ranges will be lost, but at least if the range is good you can get it back.
Here's a script that I wrote a while ago to read as many records is possible from a corrupted table. Try it out, I hope it'll help: