mysql修复表,索引

<div id="sina_keyword_ad_area2" class="articalContent" style="color:rgb(51,51,51);font-family:Arial;">
<p style="line-height:normal;"><span style="font-size:14px;"><span style="line-height:normal;">REPAIR [LOCAL |NO_WRITE_TO_BINLOG] TABLE<span style="line-height:normal;">   <span style="line-height:normal;"><span style="line-height:normal;">tbl_name[,<span style="line-height:normal;"><span style="line-height:normal;">tbl_name]...
[QUICK] [EXTENDED] [USE_FRM]


<p style="line-height:normal;"><span style="line-height:normal;"><span style="font-size:14px;"><br style="line-height:normal;">


<p style="line-height:normal;"><span style="font-size:14px;"><span style="line-height:normal;">repair  table用于修复被破坏的表。默认情况下,<span style="line-height:normal;">repair  table与<span style="line-height:normal;">myisamchk--recover<span style="line-height:normal;"><span style="line-height:normal;"><span style="line-height:normal;">tbl_name具有相同的效果。repair
 table对<span style="line-height:normal;">MyISAM和<span style="line-height:normal;">ARCHIVE表起作用。请参见<a style="color:rgb(51,102,153);">15.1节,“MyISAM存储引擎”<span style="line-height:normal;">,<a style="color:rgb(51,153);">15.8节,“ARCHIVE存储引擎”。


<p style="line-height:normal;"><span style="font-size:14px;">通常,您基本上不必运行此语句。但是,如果灾难发生,<span style="line-height:normal;"><span style="color:rgb(51,51);font-family:Arial;font-size:14px;">repair  table很有可能从<span style="line-height:normal;">MyISAM表中找回所有数据。如果您的表经常被破坏,您应该尽力找到原因,以避免使用<span style="line-height:normal;"><span style="color:rgb(51,51);font-family:Arial;font-size:14px;">repair
 table。请参见<a style="color:rgb(51,153);">A.4.2节,“如果MySQL依然崩溃,应作些什么”。同时也见<a style="color:rgb(51,153);">15.1.4节,“MyISAM表方面的问题”。


<p style="line-height:normal;"><span style="font-size:14px;">本语句会返回一个含有以下列的表:


<table style="width:628px;table-layout:auto !important;"><tbody style="line-height:normal;">
<tr style="line-height:normal;">
<td style="font-family:Arial;line-height:normal;visibility:visible !important;">
<p style="line-height:normal;"><span style="line-height:normal;"><span style="font-size:14px;">列


</td>
<td style="font-family:Arial;line-height:normal;visibility:visible !important;">
<p style="line-height:normal;"><span style="line-height:normal;"><span style="font-size:14px;">值


</td>
</tr>
<tr style="line-height:normal;">
<td style="font-family:Arial;line-height:normal;visibility:visible !important;">
<p style="line-height:normal;"><span style="line-height:normal;"><span style="font-size:14px;">Table


</td>
<td style="font-family:Arial;line-height:normal;visibility:visible !important;">
<p style="line-height:normal;"><span style="font-size:14px;">表名称


</td>
</tr>
<tr style="line-height:normal;">
<td style="font-family:Arial;line-height:normal;visibility:visible !important;">
<p style="line-height:normal;"><span style="line-height:normal;"><span style="font-size:14px;">Op


</td>
<td style="font-family:Arial;line-height:normal;visibility:visible !important;">
<p style="line-height:normal;"><span style="line-height:normal;"><span style="font-size:14px;">进行修复


</td>
</tr>
<tr style="line-height:normal;">
<td style="font-family:Arial;line-height:normal;visibility:visible !important;">
<p style="line-height:normal;"><span style="line-height:normal;"><span style="font-size:14px;">Msg_type


</td>
<td style="font-family:Arial;line-height:normal;visibility:visible !important;">
<p style="line-height:normal;"><span style="line-height:normal;"><span style="font-size:14px;">状态、错误、信息或警告之一


</td>
</tr>
<tr style="line-height:normal;">
<td style="font-family:Arial;line-height:normal;visibility:visible !important;">
<p style="line-height:normal;"><span style="line-height:normal;"><span style="font-size:14px;">Msg_text


</td>
<td style="font-family:Arial;line-height:normal;visibility:visible !important;">
<p style="line-height:normal;"><span style="font-size:14px;">消息


</td>
</tr>

语句会产生多行的信息。上一行含有一个状态值。通常应为。如果您没有得到,您应该尝试使用修复表,因为尚不会执行所有的选项。我们计划在将来使它的灵活性更强。

,则会尝试只修复索引树。这种类型的修复与使用相似。

会一行一行地创建索引行,代替使用分类一次创建一个索引。这种类型的修复与使用normal;">myisamchk--safe-recover相似。

normal;">normal;">,还有一种normal;">USE_FRM模式可以利用。如果normal;">.MYI索引文件缺失或标题被破坏,则使用此模式。在这种模式下,normal;">MysqL可以使用来自normal;">.frm文件重新创建normal;">.MYI文件。这种修复不能使用normal;">myisamchk来完成。注释:只能在您不能使用常规normal;">repair模式是,才能使用此模式。normal;">.MYI标题包含重要的表元数据(特别是,当前的normal;">AUTO_INCREMENT值和normal;">Delete链接)。这些元数据在normal;">REPAIR...USE_FRM中丢失。如果表被压缩,则不能使用normal;">USE_FRM。因为本信息也存储在normal;">.MYI文件中。

normal;">normal;">语句被写入二进制日志中,除非使用了自选的normal;">NO_WRITE_TO_binlog关键词(或其别名normal;">LOCAL)。

normal;">normal;">运行过程中,服务器停机,则在重新启动之后,在执行其它操作之前,您必须立刻对表再执行一个normal;">语句。(通过制作一个备份来启动是一个好办法。)再最不利情况下,您可以有一个新的干净的索引文件,不含有关数据文件的信息。然后,您执行的下一个操作会覆盖数据文件。这很少发生,但是是有可能的。

normal;">

normal;">

normal;">normal;">normal;">MysqL repair table-Can’t open file:‘[Table]mytable.MYI’.
normal;">   

normal;">

normal;">错误信息,却不知道怎么解决他,下面我们做个介绍:

normal;">normal;"> 多数情况下,MysqL" rel="nofollow" class="replace_word" title="MysqL知识库" style="color:rgb(223,52);text-decoration:none;font-weight:bold;">数据库被破坏只是指索引文件受到了破坏,真正的数据被破坏掉的情况非常少。大多数形式的数据库破坏的的修复相当简单。
normal;"> 和前面的校验一样,修复的方式也有三种。

normal;">方法只对MyISAM格式的表有效。其他类型的损坏需要从备份中恢复。

normal;"> sqlstatement(MysqL服务必须处于运行状态)。
normal;">   2,命令MysqLcheck(MysqL服务可以处于运行状态)。
normal;">   3,命令myisamchk(必须停掉MysqL服务,或者所操作的表处于不活动状态)。

normal;">

normal;">normal;">

normal;">

normal;">

normal;">normal;">   用”repair table”方式修复

normal;">normal;">  

normal;">normal;">    

normal;">normal;">     QUICK 用在数据表还没被修改的情况下,速度最快
normal;">     EXTENDED 试图去恢复每个数据行,会产生一些垃圾数据行,万般无奈的情况下用
normal;">     USE_FRM 用在.MYI文件丢失或者头部受到破坏的情况下。利用.frm的定义来重建索引

normal;">文件丢失或者头部受到破坏时,这样的方式不管用,例如:

normal;">

normal;">

normal;"> mytable;
normal;">     +————————-+——–+———-+—————————————————————————————+
normal;">     | Table              | Op   | Msg_type   | Msg_text               |
normal;">     +————————-+——–+———-+—————————————————————————————+
normal;">     | sports_results.mytable   |repair    |error    | Can’t find file: ‘mytable.MYI’ (errno: 2) |
normal;">     +————————-+——–+———-+—————————————————————————————+
normal;">   

normal;">文件丢失或者其头部遭到了破坏,为了利用相关定义文件来修复,需要用USE_FRM选项。例如:

normal;"> mytable USE_FRM;
normal;">     +————————-+——–+———-+————————————————————————————+
normal;">     | Table           | Op   | Msg_type  |Msg_text                                       |
normal;">     +————————-+——–+———-+————————————————————————————+
normal;">     | sports_results.mytable   |repair   |warning     | Number of rowschanged from 0 to 2 |
normal;">     | sports_results.mytable   |repair   | status     | OK                                            |
normal;">     +————————-+——–+———-+————————————————————————————+
normal;">     我们可以看到Msg_test表项的输出信息”ok”,表名已经成功修复受损表。

normal;">

normal;">

normal;">

normal;">normal;">normal;">normal;">   MysqL内建命令MysqLcheck来修复

normal;">normal;">  

normal;">MysqL服务在运行时,也可以用MysqL内建命令MysqLcheck来修复。
normal;">   

normal;">MysqLcheck -r 数据库名 表名 -uuser-ppass

normal;">MysqLcheck -rsports_results mytable -uuser -ppass

normal;">normal;">   

normal;">MysqLcheck可以一次性修复多个表。只要在数据库名后列出相应表名即可(用空格隔开)。或者数据库名后不加表名,将会修复数据库中的所有表,例如:

normal;">MysqLcheck -rsports_results mytable events -uuser -ppass

normal;">normal;">   Result:   sports_results.events OK
normal;">  
normal;">   Command: %MysqLcheck -r sports_results -uuser -ppass
normal;">     

normal;">normal;">   Result:   sports_results.events OK

normal;">

normal;">

normal;">normal;">用myisamchk修复

normal;">

normal;">normal;">   用这种方式时,MysqL服务必须停掉,或者所操作的表处于不活动状态(选项skip-external-locking没被使用)。记着一定要在相关.MYI文件的路径下或者自己定义其路径。
normal;">   

normal;">normal;">   

normal;">normal;">     –backup,-B 在进行修复前作相关表得备份

normal;">normal;">     –correct-checksum 纠正校验和

normal;">normal;">     –data-file-length=#,-D # 重建表时,指定数据文件得最大长度

normal;">normal;">     –extend-check,-e 试图去恢复每个数据行,万般无奈的情况下用

normal;">normal;">     –force,-f 当遇到文件名相同的.TMD文件时,将其覆盖掉。

normal;">normal;">     keys-used=#,-k # 指定所用的keys可加快处理速度,每个二进制位代表一个key.第一个key为0

normal;">normal;">     –recover,-r 最常用的选项,大多数破坏都可以通过它来修复。

normal;">normal;">     

normal;">

normal;">分类缓存。你可以增加key_buffer_size的值来加快修复的速度。

normal;">normal;">     –sort-recover,-n MysqL用它类分类索引,尽管结果是临时文件会非常大

normal;">normal;">     –character-sets-dir=… 包含字符集设置的目录

normal;">normal;">     –set-character-set=name 为索引定义一个新的字符集

normal;">normal;">     –tmpdir=path,-t 如果你不想用环境变量TMPDIR的值的话,可以自定义临时文件的存放位置

normal;">normal;">     –quick,-q 最快的修复方式,当数据文件没有被修改时用,当存在多键时,第二个-q将会修改 数据文件

normal;">normal;">     –unpack,-u 解开被myisampack打包的文件

normal;">

normal;">

normal;">一个例子

normal;">       - recovering (with keycache) MyISAM-table‘mytable.MYI’
normal;">

normal;">

相关文章

优化MySQL数据库发布系统存储的方法有:1.mysql库主从读写分...
使用mysql的方法:在“我的电脑”→右键→“管理”→“服务”...
在mysql中查看root用户权限的方法:1.命令行启动mysql服务;...
MySQL主从复制是用来备份一个与主数据库一样环境的从数据库,...
运行mysql的方法1.启动mysql服务,在“我的电脑”→右键→“...
开启mysql的方法1.可以通过快捷键win+r,输入cmd,打开窗口,...