After a server crash (Ubuntu 16.04), when I try to start Mysql (Mysql 5.7) using innodb_force_recovery=0
it doesn't start and error.log shows:
InnoDB: Checksum mismatch in datafile: ./panel_financiero_v2/kpis_analytics.ibd, Space ID:93, Flags: 33. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting-datadict.html for how to resolve the issue.
InnoDB: Corrupted page [page id: space=93, page number=0] of datafile './panel_financiero_v2/kpis_analytics.ibd' could not be found in the doublewrite buffer.
InnoDB: Tablespace 93 was not found at ./panel_financiero_v2/kpis_analytics.ibd.
InnoDB: Set innodb_force_recovery=1 to ignore this and to permanently lose all changes to the tablespace.
InnoDB: Cannot continue operation.
I just can start Mysql using innodb_force_recovery=6
(I can't start Mysql using innodb_force_recovery=1 as the error message advises).
The .ibd and .frm files of the troubled table are in the right directory (no empty files); I even tried (just in case, with no real hope) to delete these two files (moving them to another directory) but it doesn't work neither.
Any way to repair or recover the table (bearing in mind that innodb_force_recovery=6 starts Mysql in read-only mode and I even can't create a new table)? Any way, at least, to start mysql normally (with innodb_force_recovery=0
) even losing the information of that troubled table?
Best Answer
https://dev.mysql.com/doc/refman/5.7/en/repair-table.html says:
In other words, REPAIR TABLE does nothing for InnoDB. InnoDB has its own automatic crash recovery that it runs on startup.
But InnoDB crash recovery only works for lost changes that were in progress at the time of the crash. It uses the redo log and the doublewrite buffer to reconstruct lost dirty pages. This process cannot reconstruct data that was corrupted at rest.
The error message actually tells you what to do:
Read more details at https://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html:
Start the server with
innodb_force_recovery=1
after moving your tablespace files back where they belong.Then you can dump the table using
mysqldump
, and it should read the pages it can read, skipping corrupted pages. Then you can make a new table to import from the dump:Then re-import your dumped data.
I assume you do not need help with dumping a single table and importing the dump file.
Re your comment:
It seems like you have more extensive corruption. I suggest the following steps:
innodb_force_recovery=6
mysqldump
to dump all of the data.mysqldump
.