
Data Recovery from MySQL Table Fragments
Question:
How can you restore a MySQL database using only its .myd, .myi, and .frm files?
Answer:
For MyISAM tables, recovering data from these files is straightforward:
-
Copy the files to a database directory: Place the .frm, .myd, and .myi files in the desired database directory (e.g., /var/lib/mysql/dbname).
-
Set ownership: Change ownership of the directory to mysql:mysql (e.g., chown -R mysql:mysql /var/lib/mysql/dbname).
-
Database mismatch: The files can be restored to a different database, server, MySQL version, or architecture.
-
Permissions: Permissions are not restored with the tables, so you may need to run GRANT statements to recreate user access.
-
Repair table: While you typically only need the .frm and .myd files, repairing the table will rebuild the .myi (indexes) file.
-
Compatibility: Ensure the MySQL version you're restoring to is compatible with the files' version.
-
Table relationships: Restoring multiple tables may disrupt their relationships if the data was mixed and matched.
-
InnoDB tables: This method does not work for InnoDB tables.
The above is the detailed content of How to Recover a MySQL Database from .myd, .myi, and .frm Files?. For more information, please follow other related articles on the PHP Chinese website!