简体   繁体   English

如何从.myd,.myi,.frm文件中恢复MySQL数据库

[英]How to recover MySQL database from .myd, .myi, .frm files

如何从.myd.myi.frm文件恢复我的一个MySQL数据库?

If these are MyISAM tables, then plopping the .FRM, .MYD, and .MYI files into a database directory (eg, /var/lib/mysql/dbname ) will make that table available. 如果这些是MyISAM表,那么将.FRM,.MYD和.MYI文件放入数据库目录(例如, /var/lib/mysql/dbname )将使该表可用。 It doesn't have to be the same database as they came from, the same server, the same MySQL version, or the same architecture. 它不必是与它们相同的数据库,相同的服务器,相同的MySQL版本或相同的体系结构。 You may also need to change ownership for the folder (eg, chown -R mysql:mysql /var/lib/mysql/dbname ) 您可能还需要更改文件夹的所有权(例如, chown -R mysql:mysql /var/lib/mysql/dbname

Note that permissions ( GRANT , etc.) are part of the mysql database. 请注意,权限( GRANT等)是mysql数据库的一部分。 So they won't be restored along with the tables; 所以他们不会随桌子一起恢复; you may need to run the appropriate GRANT statements to create users, give access, etc. (Restoring the mysql database is possible, but you need to be careful with MySQL versions and any needed runs of the mysql_upgrade utility.) 您可能需要运行相应的GRANT语句来创建用户,授予访问权限等。(可以恢复mysql数据库,但需要注意MySQL版本和mysql_upgrade实用程序的任何所需运行。)

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). 实际上,您可能只需要.FRM(表结构)和.MYD(表数据),但您必须修复表以重建.MYI(索引)。

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. 当然,较新的MySQL版本会增加功能。

[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. MySQL不关心,但您的应用程序和您的用户可能会。 Also, this method does not work at all for InnoDB tables. 此外,此方法对InnoDB表完全不起作用。 Only MyISAM, but considering the files you have, you have MyISAM] 只有MyISAM,但考虑到你拥有的文件,你有MyISAM]

Note that if you want to rebuild the MYI file then the correct use of REPAIR TABLE is: 请注意,如果要重建MYI文件,则正确使用REPAIR TABLE是:

REPAIR TABLE sometable USE_FRM; 修理表可用USE_FRM;

Otherwise you will probably just get another error. 否则你可能会得到另一个错误。

I just discovered to solution for this. 我刚刚发现了解决方案。 I am using MySQL 5.1 or 5.6 on Windows 7. 我在Windows 7上使用MySQL 5.1或5.6。

  1. Copy the .frm file and ibdata1 from the old file which was located on "C:\\Program Data\\MySQL\\MSQLServer5.1\\Data" 从位于“C:\\ Program Data \\ MySQL \\ MSQLServer5.1 \\ Data”上的旧文件中复制.frm文件和ibdata1
  2. Stop the SQL server instance in the current SQL instance 停止当前SQL实例中的SQL Server实例
  3. Go to the datafolder located at "C:\\Program Data\\MySQL\\MSQLServer5.1\\Data" 转到位于“C:\\ Program Data \\ MySQL \\ MSQLServer5.1 \\ Data”的数据文件夹
  4. Paste the ibdata1 and the folder of your database which contains the .frm file from the file you want to recover. 粘贴ibdata1数据库文件夹,其中包含要恢复的文件中的.frm文件。
  5. Start the MySQL instance. 启动MySQL实例。

No need to locate the .MYI and .MYD file for this recovery. 无需为此恢复找到.MYI和.MYD文件。

One thing to note: 有一点需要注意:

The .FRM file has your table structure in it, and is specific to your MySQL version. .FRM文件中包含您的表结构,并且特定于您的MySQL版本。

The .MYD file is NOT specific to version, at least not minor versions. .MYD文件并非特定于版本,至少不是次要版本。

The .MYI file is specific, but can be left out and regenerated with REPAIR TABLE like the other answers say. .MYI文件是特定的,但可以省略并使用REPAIR TABLE重新生成,就像其他答案所说的那样。

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. 这个答案的要点是让你知道如果你有一个表的模式转储,那么你可以使用它来生成表结构,然后用备份替换那些.MYD文件,删除MYI文件,并修复它们所有。 This way you can restore your backups to another MySQL version, or move your database altogether without using mysqldump . 这样,您可以将备份还原到另一个MySQL版本,或者在不使用mysqldump情况下完全移动数据库。 I've found this super helpful when moving large databases. 移动大型数据库时,我发现这非常有用。

Simple! 简单! Create a dummy database (say abc) 创建一个虚拟数据库(比如说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. 将所有这些.myd,.myi,.frm文件复制到mysql \\ data \\ abc,其中mysql \\ data \\是存储所有数据库的.myd,.myi,.frm的地方。

Then go to phpMyadmin, go to db abc and you find your database. 然后转到phpMyadmin,转到db abc并找到您的数据库。

I think .myi you can repair from inside mysql. 我想.myi你可以从mysql里面修复。

If you see these type of error messages from MySQL: Database failed to execute query (query) 1016: Can't open file: 'sometable.MYI'. 如果您从MySQL看到这些类型的错误消息:数据库无法执行查询(查询)1016:无法打开文件:'sometable.MYI'。 (errno: 145) Error Msg: 1034: Incorrect key file for table: 'sometable'. (错误:145)错误消息:1034:表的密钥文件不正确:'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: 您可以从mysql提示符检查并修复表,如下所示:

check table sometable;
+------------------+-------+----------+----------------------------+
| Table | Op | Msg_type | Msg_text | 
+------------------+-------+----------+----------------------------+ 
| yourdb.sometable | check | warning | Table is marked as crashed | 
| yourdb.sometable | check | status | OK | 
+------------------+-------+----------+----------------------------+ 

repair table sometable;
+------------------+--------+----------+----------+ 
| Table | Op | Msg_type | Msg_text | 
+------------------+--------+----------+----------+ 
| yourdb.sometable | repair | status | OK | 
+------------------+--------+----------+----------+

and now your table should be fine: 现在你的桌子应该没问题:

check table sometable;
+------------------+-------+----------+----------+ 
| Table | Op | Msg_type | Msg_text |
+------------------+-------+----------+----------+ 
| yourdb.sometable | check | status | OK |
+------------------+-------+----------+----------+

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. 您可以将文件复制到数据文件夹的相应命名的子目录目录中,只要它是完全相同的mySQL版本并且您保留了该目录中的所有相关文件。 If you don't have all the files, I'm pretty sure you're going to have issues. 如果您没有所有文件,我很确定您会遇到问题。

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. 我找到了将文件转换为.sql文件的解决方案(然后可以将.sql文件导入服务器并恢复数据库),而无需访问/var目录,因此您不需要成为服务器管理员这样做。

It does require XAMPP or MAMP installed on your computer. 它确实需要在您的计算机上安装XAMPP或MAMP。

  • After you have installed XAMPP, navigate to the install directory (Usually C:\\XAMPP ), and the the sub-directory mysql\\data . 安装XAMPP后,导航到安装目录(通常为C:\\XAMPP )和子目录mysql\\data The full path should be C:\\XAMPP\\mysql\\data 完整路径应为C:\\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. 将包含.myd.myi.frm文件的文件夹复制并粘贴到那里。 The path to that folder should be 该文件夹的路径应该是

    C:\\XAMPP\\mysql\\data\\foldername\\.mydfiles

  • Then visit localhost/phpmyadmin in a browser. 然后在浏览器中访问localhost/phpmyadmin Select the database you have just pasted into the mysql\\data folder, and click on Export in the navigation bar. 选择刚刚粘贴到mysql\\data文件夹中的数据库,然后单击导航栏中的“导出”。 Chooses the export it as a .sql file. 选择将其导出为.sql文件。 It will then pop up asking where the save the file 然后会弹出询问保存文件的位置

And that is it! 就是这样! You (should) now have a .sql file containing the database that was originally .myd , .myi and .frm files. 您(应该)现在有一个.sql文件,其中包含最初为.myd.myi.frm文件的数据库。 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 然后,您可以通过phpMyAdmin将其导入到另一台服务器,方法是创建一个新数据库,然后在导航栏中按“导入”,然后按照步骤导入它

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 希望它能帮助别人

vim fixperms.sh 

#!/bin/sh
for D in `find . -type d`
do
        echo $D;
        chown -R mysql:mysql $D;
        chmod -R 660 $D;
        chown mysql:mysql $D;
        chmod 700 $D;
done
echo Dont forget to restart mysql: /etc/init.d/mysqld restart;

http://forums.devshed.com/mysql-help-4/mysql-installation-problems-197509.html http://forums.devshed.com/mysql-help-4/mysql-installation-problems-197509.html

It says to rename the ib_* files. 它说要重命名ib_ *文件。 I have done it and it gave me back the db. 我已经做到了,它让我回到了数据库。

对于那些安装了Windows XP且安装了MySQL服务器5.5的用户 - 数据库的位置是C:\\ Documents and Settings \\ All Users \\ Application Data \\ MySQL \\ MySQL Server 5.5 \\ data,除非您在MySql Workbench安装中更改了位置GUI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的mysql数据库中的.myd,.myi和.frm文件在哪里 - Where are my .myd, .myi and .frm files from my mysql database 有什么方法可以从 .MYI 和 .frm 文件中恢复 .MYD 文件? - Any way to recover a .MYD file from .MYI and .frm files? 从.frm文件(没有.myd和.myi,ibdada,my.ini)恢复MySQL InnoDB数据/结构 - Recover MySQL InnoDB data/structure from .frm (no .myd and .myi, ibdada, my.ini) files MySQL使用frm,myd和myi文件还原数据库功能 - MySQL restoring database functions using frm, myd and myi files 如何在没有MySQL的情况下探索mysql数据库文件(* .frm,* .myd和* .myi)? - How can I explore mysql database files (*.frm, *.myd and *.myi) without MySQL? 如何使用CPanel中每个表的.frm,.MYD和.MYI文件访问var文件夹和MySQL数据库文件夹? - How to access the var folder and a MySQL database folder with .frm, .MYD and .MYI files of each table in CPanel? 从 MYI、MYD、frm 文件中获取数据 - Getting data from MYI, MYD, frm files 从.MYD,.MYI和.frm文件还原SQL表,mysql无法找到.frm文件 - Restoring SQL tables from .MYD, .MYI and .frm files, mysql can't find .frm files 如何阅读MYI、MYD、frm - How to read MYI, MYD, frm 如何在OS X Lion中还原MySQL .frm .MYD .MYI文件 - How do I restore MySQL .frm .MYD .MYI files in OS X Lion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM