MySQL table recovery from crashed server - mysql

I managed to wipe a server by mistake but PhotoRec was kind enough to recover the .frm and .myi files from the hard drive. I now have a desktop set up with the same version of MySQL to recover the data but my question is: what do I do? I have about 160 of these files. I haven't yet reinstalled the server in case I need anything else.
Also, as I'm using PhotoRec, it doesn't provide the original filenames. If this is important, how can I get the raw data out of the files and manually rebuild the database?
Edit: I managed to get ahold of the PhotoRec source and add the capability to recover the .myd files (which a bit of digging reveals to be the actual data files), but I can't get the thing to compile, and it ain't because of my mods! Can anyone help with a 'No rule to make target' error in PhotoRec? file_http.o's the culprit.
Thanks,
Rob

MYI files are useless, these are files with secondary indexes, not your data.
PhotoRec is a nice tool, I used it a lot for multimedia recovery etc. Although it claims MYD support it never worked for me. I doubt it possibly can extract MYD files.

I dont belive you can, photorec does not support MYD, im doing an attempt with ext3grep but it always segfaults.
just posting this so someone doesnt spend time better spent on using photorec for this purpose.

Related

Restore truncated table from online server

I accidentally truncated my table from online server and I wasn't able to back up it. Please anyone help me on what should I do.
Most viable, least work:
From a backup
Check again if you have one
Ask your hoster if they do backups; their default configuration for some setups might include a backup that you are unaware of, e.g. a database backup for wordpress or a file backup if you have a vm
Viable in some situations, little work if applicable:
From binary logs. Check if they are enabled (maybe as part of your hosters default configuration, also maybe only the hoster can access them, so you may need to ask them). They contain the most recent changes to your database, and, if you are lucky, "recent" might be long enough to include everything
Less viable, more work:
Try to recover from related data, e.g. history tables, other related tables or log files (e.g. the mysql general query log or log files that your application created); you can try to analyze them to figure out what should be in your table
Least viable, most work, most expensive:
In theory, since the data is still stored on the harddrive until it is overwritten by new data, you can try to recover the data, similar to tools that find lost blocks or deleted files on your harddrive
You need to stop any activity on your harddrive to increase probability of success. This will depend on your configuration and setup. E.g., in shared hosting, freed diskspace might be overwritten by other users beyond you control, on the other hand, if you are using innodb and disabled innodb_file_per_table, the data is stored in a single file (and the disk space is not freed), so stopping your mysql server should prevent any remaining recoverable data from being overwritten.
While there are some tools to help you with that, you will likely have to pay someone to do it for you (and even then you only get back the data that hasn't been overwritten so far), so this option is most likely only viable if your data is very valuable

Recover my database structure from from files

It was my habit to uninstall easyphp without losing my database...But this time, I've uninstalled my easyphp and re-installed it again, but when I tried to view my database, I see that all tables have been lost.
Actually, my tables are all empty, because I've just finished the database conception and I did not yet begun the project online.
But the tables are about 40 table, and I don't want to recreate them again.
so I've viewed my mysql directory, and I see that *.frm files with the names of my tables.
How can I recover my tables structure (not data) from those *.frm files?
I have tried and tried to do this after reading lots of suggestions on the Internet, but the answer is no.
Either find an earlier backup or, as I had to do, redo all your tables. This is taking me about 2 hours, but I'm going to back up my files a lot more often now :)
Use this as a learning experience.

Is it wrong to backup a MySQL DB through copying its data files (.frm, .MYD, etc.)?

I read somewhere that it is, so I was wondering.
Don't do that, the .frm/.myd/.myi may be much larger than the actual data and may cause crash (data not consistence) or very hard to transfrom/recover.
Use mysqldump to transfer MySQL database.
It might or might not work, depending on the state of the data.
it should work if you stop the database completely and restart it again after the backup, but there you have a downtime.
A slightly more detailed response at askers request.
Some details of the dangers of a straight file copy:
If the database is live the database might change some of the files
before others so when you copy them you copy them you may get copies
in that are inconsistent with each other. If the database is offline
this method is probably reliable.
Advantages of using the documented methods:
Should work on future version of DBMS
Should work consistently across underlying engines
Always a consistent snapshot like copy

how to save or retrieve data from mysql when we cannot open it anymore?

I am trying to save or retrieve data from my co-workers computer. Her MySQL instance does not work anymore (cannot figure out the reasons). I would like to know if there is a way to save all the data from the databases present in her computer.
Any suggestions on how to save the data, and maybe re-install MySQL again?
You can copy the tables to another computer with a working MySQL instance, as long as the floating point format is the same on both computers (see this page for reference, covered in the first paragraph).
As long as you copy the .frm, .myd and .myi files somewhere safe, you can also try reinstalling MySQL and see if that works for you.
First of all, errors may be recoverable. If you do not have ability to recover from errors, you can try to make a plain copy of MySQL data. BUT! If tables used InnoDB engine, that will be not so easy and chance of recovery will be not so big.

Recover data from a dropped/truncated MySQL table

I just spend a few hours putting together a table full of data, and just decided to drop a WP installation in the same database. I expected WordPress to leave my table as it was and simply add the WP_* tables, but apparently the install wiped my database before installing the wordpress tables.
I have full access to the server root. Is there any way for me to recover this table?
I'm sorry, but that can't be done. Once a table is truncated or dropped everything is gone.
The only way to get it back would be recovering the database files from the disk, but that is not very reliable. To do that, you first have to find out where the MySQL's data files are (see this), then try using a file recovery tool to get them back. Good luck.
Another one who learns to back up the hard way.
If tables were MyISAM, then I agree with NullUserException - you can't recover the tables. Well, the chance is very slim.
If InnoDB - check out my presentation on slideshare - there is a tool to extract records from raw bytes stream - percona data recovery toolkit. There are examples in the presentation, your scenario is pretty much typical.
UPDATE: Data recovery toolkit moved to GitHub