如何从 .myd、.myi、.frm 文件恢复 MySQL 数据库
如何从 .myd
、.myi
、.frm
文件恢复我的 MySQL 数据库之一?
How to restore one of my MySQL databases from .myd
, .myi
, .frm
files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
通过查询
SHOW VARIABLES WHERE Variable_Name LIKE "%dir" ;
查找您的datadir
创建一个新文件夹并将
.myd、.myi、.frm
文件放入其中。检查表格。
Find your
datadir
by the query thatSHOW VARIABLES WHERE Variable_Name LIKE "%dir" ;
Create a new folder and put the
.myd, .myi, .frm
files into it.Check the tables.
对于使用 Windows XP 并安装了 MySQL Server 5.5 的用户 - 数据库的位置为 C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.5\data,除非您在 MySql Workbench 安装中更改了位置图形用户界面。
For those that have Windows XP and have MySQL server 5.5 installed - the location for the database is C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.5\data, unless you changed the location within the MySql Workbench installation GUI.
如果这些是 MyISAM 表,则将 .FRM、.MYD 和 .MYI 文件放入数据库目录(例如,
/var/lib/mysql/dbname
)将使该表可用。 它不必是来自相同的数据库、相同的服务器、相同的 MySQL 版本或相同的体系结构。 您可能还需要更改文件夹的所有权(例如,chown -R mysql:mysql /var/lib/mysql/dbname)请注意,权限(GRANT 等) )是
mysql
数据库的一部分。 因此它们不会与表格一起恢复; 您可能需要运行适当的GRANT
语句来创建用户、授予访问权限等。(可以恢复mysql
数据库,但您需要小心MySQL版本和任何需要的mysql_upgrade
实用程序的运行。)实际上,您可能只需要 .FRM(表结构)和 .MYD(表数据),但您必须修复表才能重建 .MYI (索引)。
唯一的限制是,如果您要降级,您最好检查发行说明(并且可能运行修复表)。 当然,较新的 MySQL 版本会添加一些功能。
[虽然这应该是显而易见的,但如果您混合和匹配表,那么这些表之间关系的完整性就是您的问题; MySQL 不会关心,但您的应用程序和您的用户可能会关心。 另外,这个方法对于InnoDB表根本不起作用。 只有MyISAM,但考虑到你拥有的文件,你有MyISAM]
If these are MyISAM tables, then plopping the .FRM, .MYD, and .MYI files into a database directory (e.g.,
/var/lib/mysql/dbname
) will make that table available. It doesn't have to be the same database as they came from, the same server, the same MySQL version, or the same architecture. You may also need to change ownership for the folder (e.g.,chown -R mysql:mysql /var/lib/mysql/dbname
)Note that permissions (
GRANT
, etc.) are part of themysql
database. So they won't be restored along with the tables; you may need to run the appropriateGRANT
statements to create users, give access, etc. (Restoring themysql
database is possible, but you need to be careful with MySQL versions and any needed runs of themysql_upgrade
utility.)Actually, you probably just need the .FRM (table structure) and .MYD (table data), but you'll have to repair table to rebuild the .MYI (indexes).
The only constraint is that if you're downgrading, you'd best check the release notes (and probably run repair table). Newer MySQL versions add features, of course.
[Although it should be obvious, if you mix and match tables, the integrity of relationships between those tables is your problem; MySQL won't care, but your application and your users may. Also, this method does not work at all for InnoDB tables. Only MyISAM, but considering the files you have, you have MyISAM]
我刚刚发现解决这个问题的方法。 我在 Windows 7 上使用 MySQL 5.1 或 5.6。
无需查找 .MYI 和 .MYD 文件即可进行此恢复。
I just discovered to solution for this. I am using MySQL 5.1 or 5.6 on Windows 7.
No need to locate the .MYI and .MYD file for this recovery.
请注意,如果要重建 MYI 文件,那么 REPAIR TABLE 的正确用法是:
REPAIR TABLE sometable USE_FRM;
否则你可能会得到另一个错误。
Note that if you want to rebuild the MYI file then the correct use of REPAIR TABLE is:
REPAIR TABLE sometable USE_FRM;
Otherwise you will probably just get another error.
上面的描述不足以让事情为我工作(可能是密集的或懒惰的),所以一旦我找到了未来可以帮助我的答案,我就创建了这个脚本。 希望它对其他人有帮助
The above description wasn't sufficient to get things working for me (probably dense or lazy) so I created this script once I found the answer to help me in the future. Hope it helps others
我认为.myi你可以从mysql内部修复。
如果您从 MySQL 看到这些类型的错误消息:
数据库无法执行查询(query)1016:无法打开文件:'sometable.MYI'。 (错误号:145)
错误消息:1034:表的密钥文件不正确:“sometable”。 尝试修复它
那么您可能有一个崩溃或损坏的表。
您可以从 mysql 提示符检查并修复表,如下所示:
现在您的表应该没问题了:
I think .myi you can repair from inside mysql.
If you see these type of error messages from MySQL:
Database failed to execute query (query) 1016: Can't open file: 'sometable.MYI'. (errno: 145)
Error Msg: 1034: Incorrect key file for table: 'sometable'. Try to repair it
thenb you probably have a crashed or corrupt table.
You can check and repair the table from a mysql prompt like this:
and now your table should be fine:
您可以将文件复制到数据文件夹的适当命名的子目录中,只要它是完全相同的 mySQL 版本,并且您已保留该目录中的所有关联文件。 如果您没有所有文件,我很确定您会遇到问题。
You can copy the files into an appropriately named subdirectory directory of the data folder as long as it is the EXACT same version of mySQL and you have retained all of the associated files in that directory. If you don't have all the files, I'm pretty sure you're going to have issues.
http://forums.devshed.com/mysql- help-4/mysql-installation-problems-197509.html
它说重命名 ib_* 文件。 我已经完成了,它还给了我数据库。
http://forums.devshed.com/mysql-help-4/mysql-installation-problems-197509.html
It says to rename the ib_* files. I have done it and it gave me back the db.
简单的! 创建一个虚拟数据库(例如 abc)
将所有这些 .myd、.myi、.frm 文件复制到 mysql\data\abc,其中 mysql\data\ 是存储所有数据库的 .myd、.myi、.frm 的位置。
然后转到 phpMyadmin,转到 db abc,然后找到您的数据库。
Simple! Create a dummy database (say abc)
Copy all these .myd, .myi, .frm files to mysql\data\abc wherein mysql\data\ is the place where .myd, .myi, .frm for all databases are stored.
Then go to phpMyadmin, go to db abc and you find your database.
需要注意的一件事:
.FRM 文件中包含您的表结构,并且特定于您的 MySQL 版本。
.MYD 文件不特定于版本,至少不特定于次要版本。
.MYI 文件是特定的,但可以省略并使用
REPAIR TABLE
重新生成,就像其他答案所说的那样。这个答案的目的是让您知道,如果您有表的模式转储,那么您可以使用它来生成表结构,然后用您的备份替换这些 .MYD 文件,删除 MYI 文件并修复它们全部。 通过这种方式,您可以将备份恢复到另一个 MySQL 版本,或者完全移动数据库,而无需使用
mysqldump
。 我发现这在移动大型数据库时非常有用。One thing to note:
The .FRM file has your table structure in it, and is specific to your MySQL version.
The .MYD file is NOT specific to version, at least not minor versions.
The .MYI file is specific, but can be left out and regenerated with
REPAIR TABLE
like the other answers say.The point of this answer is to let you know that if you have a schema dump of your tables, then you can use that to generate the table structure, then replace those .MYD files with your backups, delete the MYI files, and repair them all. This way you can restore your backups to another MySQL version, or move your database altogether without using
mysqldump
. I've found this super helpful when moving large databases.我找到了一种将文件转换为
.sql
文件的解决方案(然后您可以将.sql
文件导入到服务器并恢复数据库),而无需访问/var
目录,因此您也不需要成为服务器管理员来执行此操作。它确实需要在您的计算机上安装 XAMPP 或 MAMP。
C:\XAMPP
)和子目录mysql\data
。 完整路径应该是C:\XAMPP\mysql\data
在里面您将看到您创建的任何其他数据库的文件夹。 复制& 将充满
.myd
、.myi
和.frm
文件的文件夹粘贴到其中。 该文件夹的路径应该是C:\XAMPP\mysql\data\foldername\.mydfiles
然后在浏览器中访问
localhost/phpmyadmin
。 选择刚刚粘贴到mysql\data
文件夹中的数据库,然后单击导航栏中的“导出”。 选择将其导出为.sql
文件。 然后会弹出询问保存文件的位置就是这样! 您(应该)现在有一个
.sql
文件,其中包含最初为.myd
、.myi
和.frm 文件。 然后,您可以通过 phpMyAdmin 将其导入到另一台服务器,方法是创建一个新数据库并按导航栏中的“导入”,然后按照步骤导入它
I found a solution for converting the files to a
.sql
file (you can then import the.sql
file to a server and recover the database), without needing to access the/var
directory, therefore you do not need to be a server admin to do this either.It does require XAMPP or MAMP installed on your computer.
C:\XAMPP
), and the the sub-directorymysql\data
. The full path should beC:\XAMPP\mysql\data
Inside you will see folders of any other databases you have created. Copy & Paste the folder full of
.myd
,.myi
and.frm
files into there. The path to that folder should beC:\XAMPP\mysql\data\foldername\.mydfiles
Then visit
localhost/phpmyadmin
in a browser. Select the database you have just pasted into themysql\data
folder, and click on Export in the navigation bar. Chooses the export it as a.sql
file. It will then pop up asking where the save the fileAnd that is it! You (should) now have a
.sql
file containing the database that was originally.myd
,.myi
and.frm
files. You can then import it to another server through phpMyAdmin by creating a new database and pressing 'Import' in the navigation bar, then following the steps to import it