Home >Database >Mysql Tutorial >How Can I Restore a MySQL Database from its .frm, .myd, and .myi Files?

How Can I Restore a MySQL Database from its .frm, .myd, and .myi Files?

DDD
DDDOriginal
2024-12-20 11:28:09819browse

How Can I Restore a MySQL Database from its .frm, .myd, and .myi Files?

Restoring a MySQL Database from Table Files (.myd, .myi, .frm)

If you possess table files (.myd, .myi, and .frm) for your MySQL database, restoring it is straightforward, particularly if the tables are in the MyISAM format.

To restore a MyISAM database:

  1. Place the Table Files in a Database Directory:

    • Copy the .frm, .myd, and .myi files into a directory within your MySQL database directory (e.g., /var/lib/mysql/dbname).
  2. Adjust File Ownership:

    • Ensure that the folder where the files are located has the correct ownership (e.g., chown -R mysql:mysql /var/lib/mysql/dbname).
  3. Repair the Table:

    • While you technically only need the .frm and .myd files, repairing the table will rebuild the .myi (indexes). To repair the table, run the following command:

      mysqlcheck -r <table_name>

Considerations:

  • Permissions and grants are not restored with this method. You may need to reissue GRANT statements to configure user access.
  • Downgrading MySQL versions may require additional caution and potentially running repair table.
  • This method is only applicable for MyISAM tables. InnoDB tables cannot be restored from these file types.
  • Mixing and matching tables may compromise relationship integrity.

The above is the detailed content of How Can I Restore a MySQL Database from its .frm, .myd, and .myi Files?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn