in Web and Tech, Work

Recovering your MySQL databases from raw files

Recently a buddy asked for my help to recover a MySQL database he needed for work. He only had a set of raw files which mainly consisted of files with the following extensions: .MYD, .MYI and .frm. I somehow knew MySQL stored databases using these file sets but never have I had to recover data using just these. Often, there are compressed SQL files as backups from which to recover from.

Here are the steps I took to recover the database, a summation of several pages of various solutions Google has offered.

1. Make sure you have all the files (.frm, .MYD, .MYI)
2. Make sure all the files are in one folder (.e.g. my_database/)
3. Locate MySQL data file store (default Ubuntu: /var/lib/mysql)
4. Copy entire folder in MySQL data file store
sudo scp my_database /var/lib/mysql
Impt: The name of your folder will be the name of the database. So make sure that before you copy to the data file store, there is no existing folder of the same name.
5. Change the permissions of the newly copied folder
sudo chown -R mysql:mysql /var/lib/mysql/my_database
6. Run mysqlcheck repair to ensure the databases are free of problems.
mysqlcheck -u root -p --auto-repair --all-databases
7. And you’re good!

Write a Comment

Comment