5

Situation: I have a MySQL database with 104 tables, running locally on XAMPP on windows 7. All the tables have InnoDB engine. XAMPP MySQL is running as windows service. As front end I have PHP (CodeIgniter).

Problem: Last night as usual I stopped working on the project and shutdown the windows normally. Today in the morning I got error table MY_TALBE does not exists in the browser. show tables on console shows the table name, but desc MY_TABLE and select * from MY_TABLE says unknown table. I tried create table MY_TABLE(...) but I had error as table MY_TABLE already exists, so I tried drop table MY_TABLE but it said Unknown table MY_TABLE! I tried mysqlcheck.exe for repair and check, they failed both, but after that, show tables does not show the table name any longer. I need to mention I did not change/move/delete/rename any of mysql files.

Question: Is it possible to recover/repair MY_TABLE, or at least how to drop and create it again (without dropping the database and re-crteating it again)?

4

This situation sounds a lot like a post I answered two years ago (InnoDB table SELECT returns ERROR 2006 (HY000): MySQL server has gone away (after power outage))

First, here is the InnoDB Architecture

InnoDB Architecture

In that post, I basically point out that the metadata of the table is still present inside the system tablespace file ibdata1.

When you ran SHOW TABLES;, all mysqld did was report the .frm files. It is possible to create the table as MyISAM because it has no attachments to ibdata1 or any other metadata. Yet, you cannot convert it to InnoDB because the metadata somehow imagines that the .frm and some tablespace_id is attached to the table name. Based on my old post, I would just mysqldump all the other tables and call you table a lost cause. However, Percona has the Data Recovery Toolkit for just such an occasion.

In the webpage about the Data Recovery Toolkit says

The Percona Data Recovery Tool for InnoDB is a free toolkit for recovering lost or corrupted data from InnoDB tables. It provides a way to extract InnoDB's data from files or raw devices in a tab-separated format when standard InnoDB recovery cannot be used for some reason such as a dropped table or severe corruption that prevents InnoDB from recognizing the data. It can be used for MySQL recovery to retrieve deleted tables, recover previous versions of updated rows, or fix InnoDB file corruption after a hardware failure such as a memory fault or bad cabling.

Percona has used these tools to perform MySQL data recovery for many customers, including extremely large datasets. Although the tools are powerful, performing InnoDB data recovery correctly requires expert knowledge of the InnoDB storage format and source code plus experience, and intuition. Percona can help with our data recovery service.

I have not used it, but if Percona made it, you should give it a try.

If you have a backup of that lost table (in the form of a mysqldump), you should carry out the steps from my old post and then load the backup of the lost table.

SUGGESTION

Once you get this situation squared away, you should tune InnoDB to flush changes to disk.

[mysqld]
innodb_fast_shutdown=0
innodb_max_dirty_pages_pct=0
innodb_buffer_pool_dump_at_shutdown=1
innodb_buffer_pool_load_at_startup=1

That way, when you shutdown mysql, InnoDB can more thoroughly flush changes.

If you want even better assurance of InnoDB being flushed to disk, you should use MySQL in Linux.

  • Thanks for answer. I could recover my DB using mysqldump. Only about Percona, as far as my search says it does not have a windows version, and I am running windows. Is there any alternate for that? – Musa Haidari Apr 7 '14 at 6:03
2

Yes, you can try to repair your innoDB table

First you should backup your tables.

  1. Stop your MySQL service

  2. Add or change the value on your my.ini innodb_force_recovery option.

[mysqld]
innodb_force_recovery = 1 [for better crash recovery]
  1. backup all the data from "C:\xampp\mysql\data" to another folder, example: "C:\xampp\mysql\databackup" or

  2. take mysqldump of the database or table which has crash.

  3. Start your mysql service.

Levels 0 to 4 are safe, but if you want to use levels 5 o 6 you can lose some data

  1. comment innodb_force_Recovery= 1 under my.ini file

  2. restore the table or database.

Chek the Forcing InnoDB Recovery in MySQL documentation: http://dev.mysql.com/doc/refman/5.0/en/forcing-innodb-recovery.html

-1

You can try creating a new table according to old one's structure. Not sure if this will realy help as you say that your original table is corrupted:

CREATE TABLE `new_table` LIKE `MY_TABLE`;

If new table is ok, you can drop old one:

DROP TABLE `MY_TABLE`;

Otherwise you will have to drop the table (with the command above) and recreate it manually or from a backup.

  • 1
    I already mentioned I can not drop the table nor create a table with the same name. – Musa Haidari Apr 7 '14 at 5:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.