开发者

How can I recover MySQL tables from data files?

I've got a database (all MyISAM tables) and the machine where MySQL was running is no longer bootable. However, we have all the MySQL data files from the data directory. How can I restore the data from the MYD and FRM files, or whatever other files I should be looking at in the data directory?

I've been doing some searching on this and it sounds like for MyISAM I should just be able to copy the database subdirectory from the old MySQL data directory to the new MySQL data directory. However, that's not working for me. A database with the name of the database I'm trying to recover shows up in the list of databases in phpMyAdmin, but all the tables show "in use" and have no information (e.g., number of rows, number of bytes, column information, etc.). Any operation on those tables (e.g., SELECT * FROM {table}, REPAIR {table}, CHECK {table}) returns a "no such table" error.

One of the tools I ran across in my search is DBACentral by MicroOLAP. It's got component that's supposed to restore data from FRM/MYD files, but when I tried to run it, it didn't list any tables that it could recover from my FRM/MYD files.

This is on a developer workstation that's running Vista Business 32bit. MySQL version is 5.0.27. After fixing the machine, I went and got the exact same version of MySQL (v5.0.27), thinking that if I'm just going to drop in the binary data files I should do it with the same version of MySQL. It still didn't work.

Any 开发者_StackOverflowinsights would be greatly appreciated... thanks!

-Josh


  1. Install the same version of mysql.
  2. Remove mysql directory from data directory of the server and copy it from the crashed server. This is the key element
  3. copy directory of database you want to recover into data directory of new server
  4. start mysql.
  5. switch to mysql database: USE mysql; and run REPAIR TABLE <table name> on every table.
  6. Do the same with database you want to recover

tip: make sure the 2 directories have the same permissions like data directory

If you did not save mysql database (mysql directory in your old server's data dir, then you can try to:

  1. create database with the same name as database you want to recover.
  2. Then you can create each table (it would be good to use the same structure - you'd have bigger chance of recovery).
  3. then stop mysql server and delete files from database directory and overwrite them with files from old server
  4. start mysql and repair each table.


I wound up giving up. I think the answer is that, with my particular version of MySQL, this doesn't work. Hopefully things have improved since then.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜