Restoring MyISAM Tables from FRM, MYD, and MYI Files in MySQL 5.7
Procedure Overview
| Phase | Action |
|---|---|
| 1 | Authenticate with the database server |
| 2 | Provision a new schema |
| 3 | Position raw files into the data directory |
| 4 | Reconcile table metadata and indexes |
Phase 1: Authenticate with the database server
Establish a connection to the MySQL instance using administrative credentials:
mysql -h localhost -u admin_user -p
The -p flag triggers a secure password prompt.
Phase 2: Provision a new schema
Instantiate a database container for the target data:
CREATE DATABASE restored_db CHARACTER SET utf8mb4;
USE restored_db;
Phase 3: Position raw files into the data directory
Locate the MySQL data storage path and transfer the backup files (.frm, .MYD, .MYI) into the newly created schema directory. Execute these commands in the system terminal:
sudo cp /path/to/backup/target_table.frm /var/lib/mysql/restored_db/
sudo cp /path/to/backup/target_table.MYD /var/lib/mysql/restored_db/
sudo cp /path/to/backup/target_table.MYI /var/lib/mysql/restored_db/
sudo chown mysql:mysql /var/lib/mysql/restored_db/target_table.*
Adjusting file ownership ensures the MySQL daemon has read/write permissions.
Phase 4: Reconcile table metadata and indexes
Return to the MySQL shell and force the server to recognize the newly placed files and validate their structural integrity:
REPAIR TABLE restored_db.target_table USE_FRM;
This operation reconstructs the index information from the .frm and .MYD files if the .MYI file is corrupted, bringing the table online.