MySQL 如何修复损坏的表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6177246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:05:34  来源:igfitidea点击:

How to repair corrupted table

mysql

提问by ssbecse

I have the mysqltable called Sample. I have edited the file /var/lib/mysql/Sample.MYIwith some values. Now check TABLE Sample query shows as

我有mysql一张名为Sample的表。我已经/var/lib/mysql/Sample.MYI用一些值编辑了文件。现在检查表示例查询显示为

Incorrect key file for table 'Sample'; try to repair it

表 'Sample' 的密钥文件不正确;尝试修复它

To repair this, i have tried using the following command myisamchk -r Sample.MYI. but the result is "myisamchk:

为了修复这个问题,我尝试使用以下命令myisamchk -r Sample.MYI。但结果是“myisamchk:

error: Got error 140 when trying to recreate indexfile MyISAM-table Sample.MYIis not fixed because of errors".

错误:尝试重新创建索引文件时出现错误 140 MyISAM-tableSample.MYI由于错误而未修复”。

Now how to repair this table ?

现在如何修理这张桌子?

回答by Johan

Just in case you don't have backup, don't have the original file and cannot redownload it, here are some links that might help you:

以防万一您没有备份,没有原始文件并且无法重新下载,这里有一些链接可能会对您有所帮助:

http://www.felipecruz.com/repair-mysql-database.php
http://dev.mysql.com/doc/refman/5.0/en/myisam-repair.html(see also links at the bottom of this page)
http://forums.mysql.com/read.php?21,362974,362974

http://www.felipecruz.com/repair-mysql-database.php
http://dev.mysql.com/doc/refman/5.0/en/myisam-repair.html(另见本页底部的链接)
http://forums.mysql.com/read.php?21,362974,362974

The following command will recreate .myi files from scratch:

以下命令将从头开始重新创建 .myi 文件:

REPAIR TABLE tablename USE_FRM

enter image description hereBe careful with this though, this page: http://dev.mysql.com/doc/refman/5.5/en/repair-table.htmlsays:

在此处输入图片说明不过要小心,这个页面:http: //dev.mysql.com/doc/refman/5.5/en/repair-table.html说:

Use the USE_FRM option only if you cannot use regular REPAIR modes! Telling the server to ignore the .MYI file makes important table metadata stored in the .MYI unavailable to the repair process, which can have deleterious consequences:[.....]

仅当您无法使用常规 REPAIR 模式时才使用 USE_FRM 选项!告诉服务器忽略 .MYI 文件会使存储在 .MYI 中的重要表元数据无法用于修复过程,这可能会产生有害的后果:[.....]

And finally how to redo this in different ways:

最后如何以不同的方式重做:

http://www-users.cs.york.ac.uk/susan/joke/foot.htm

http://www-users.cs.york.ac.uk/susan/joke/foot.htm

回答by minhas23

Check the status of the corrupted table

检查损坏表的状态

check table tablename;

e.g

例如

mysql> check table realtime_clicks_update;
+--------------------------------+-------+----------+----------+
| Table                          | Op    | Msg_type | Msg_text |
+--------------------------------+-------+----------+----------+
| logdata.realtime_clicks_update | check | status   | OK       |
+--------------------------------+-------+----------+----------+

If status is not OK then repair it using following command

如果状态不正常,则使用以下命令修复它

mysql> repair table tablename;

回答by Lightness Races in Orbit

Why did you edit the .MYIfile? You're not supposed to do that.

你为什么编辑.MYI文件?你不应该那样做。

Restore from backups then re-apply the changes in the proper fashion.

从备份中恢复,然后以适当的方式重新应用更改。

回答by Tudor Constantin

put back the original Sample.MYI file :)

放回原来的 Sample.MYI 文件 :)

回答by Shanaya

REPAIR TABLE Statement can help you in recovering the table. This statement works for MyISAM, Archive and CSV tables. Command is as follows: REPAIR TABLE tbl_name [, tbl_name]... [QUICK] [EXTENDED] [USE_FRM] Where QUICK: If you use this option then repair table tries to repair only the index file and not the data file. EXTENDED: If you use this option then MySQL creates the index row by row instead of creating one index at a time with sorting. USE_FRM: This option is used if the .MYI index file is missing or if its header is corrupted.

REPAIR TABLE 语句可以帮助您恢复表。此语句适用于 MyISAM、存档和 CSV 表。命令如下: REPAIR TABLE tbl_name [, tbl_name]... [QUICK] [EXTENDED] [USE_FRM] 其中QUICK:如果使用此选项,则修复表尝试仅修复索引文件而不是数据文件。扩展:如果您使用此选项,则 MySQL 将逐行创建索引,而不是通过排序一次创建一个索引。USE_FRM:如果 .MYI 索引文件丢失或其标头损坏,则使用此选项。

In this case you can try USE_FRM option to repair the table. If the above mentioned method doesn't work then you can try using this MySQL repair tool from Stellar, but you should first try with the manual method and should use this method only in case if you want a quick solution to the problem. The software claims to repair the InnoDB and MyISAM tables of MySQL database along with safely restoring all inaccessible database objects including primary keys, views, triggers, tables, etc. in the original format.

在这种情况下,您可以尝试使用 USE_FRM 选项来修复表。如果上述方法不起作用,那么您可以尝试使用 Stellar 的此 MySQL 修复工具,但您应该首先尝试使用手动方法,并且仅在您想要快速解决问题时才应使用此方法。该软件声称可以修复 MySQL 数据库的 InnoDB 和 MyISAM 表,并以原始格式安全地恢复所有无法访问的数据库对象,包括主键、视图、触发器、表等。