温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》
  • 首页 > 
  • 教程 > 
  • 数据库 > 
  • MySQL数据库中怎么修复.frm文件、.MYD文件和.MYI文件

MySQL数据库中怎么修复.frm文件、.MYD文件和.MYI文件

发布时间:2021-07-24 17:20:19 来源:亿速云 阅读:578 作者:Leah 栏目:数据库

这篇文章给大家介绍MySQL数据库中怎么修复.frm文件、.MYD文件和.MYI文件,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

  MySQL数据库.frm文件、.MYD文件和.MYI文件怎么修复

  要检查一个表的错误,只需要运行myisamchk(在MySQL的bin目录下)并提供文件的位置和表名,或者是表的索引文件名:

  %myisamchk/usr/local/mysql/var/dbName/tblName%myisamchk/usr/local/mysql/var/dbName/tblName.MYI

  上面的两个命令都可以执行对指定表的检查。要检查数据库中所有的表,可以使用通配符:

  %myisamchk/usr/local/mysql/var/dbName*.MYI

  如果不带任何选项,myisamchk将对表文件执行普通的检查。如果你对一个表有怀疑,但是普通的检查不能发现任何错误,你可以执行更彻底的检查(但是也更慢!),这需要使用--extend-check选项:

  %myisamchk--extend-check/path/to/tblName

  对错误的检查是没有破坏性的,这意味着你不必担心执行对你的数据文件的检查会使已经存在的问题变得更糟。另一方面,修复选项,虽然通常也是安全的,但是它对你的数据文件的更改是无法撤消的。因为这个原因,我们强烈推荐你试图修复一个被破坏的表文件时首先做个备份,并确保在制作这个备份之前你的MySQL服务是关闭的。

  在windows2003下通过命令提示符,输入:

  注:此为记录我当时操作的全部过程

  D:\DocumentsandSettings\Administrator>c:C:\>cdmysqlC:\mysql>cddataC:\mysql\data>cdhw_enterpriceC:\mysql\data\hw_enterprice>myisamchkfunction_products.frm

  'myisamchk'不是内部或外部命令,也不是可运行的程序或批处理文件。

  C:\mysql\data\hw_enterprice>cd\C:\>cdmysqlC:\mysql>cdbin

  注:查看myisamchk的帮助信息

  C:\mysql\bin>myisamchkmyisamchkVer2.6forWin95/Win98ati32ByMonty,foryourprofessionaluseThissoftwarecomeswithNOWARRANTY:seethePUBLICfordetails.Description,checkandrepairofISAMtables.UsedwithoutoptionsalltablesonthecommandwillbecheckedforerrorsUsage:myisamchk[OPTIONS]tables[.MYI]Globaloptions:-#,--debug=...Outputdebuglog.Oftenthisis'd:t:o,filename'-,--helpDisplaythishelpandexit.-O,--set-variablevar=optionChangethevalueofavariable.Pleasenotethatthisoptionisdeprecated;youcansetvariablesdirectlywith'--variable-name=value'.-t,--tmpdir=pathPathfortemporaryfiles-s,--silentOnlyprinterrors.Onecanusetwo-stomakemyisamchkverysilent-v,--verbosePrintmoreinformation.Thiscanbeusedwith--descriptionand--check.Usemany-vformoreverbosity!-V,--versionPrintversionandexit.-w,--waitWaitiftableislocked.Checkoptions(checkisthedefaultactionformyisamchk):-c,--checkChecktableforerrors-e,--extend-checkCheckthetableVERYthroughly.Onlyusethisinextremecasesasmyisamchkshouldnormallybeabletofindoutifthetableisokevenwithoutthisswitch-F,--fastCheckonlytablesthathaven'tbeenclosedproperly-C,--check-only-changedCheckonlytablesthathavechangedsincelastcheck-f,--forceRestartwith'-r'ifthereareanyerrorsinthetable.Stateswillbeupdatedaswith'--update-state'-i,--informationPrintstatisticsinformationabouttablethatischecked-m,--medium-checkFasterthanextend-check,butonlyfinds99.99%ofallerrors.Shouldbegoodenoughformostcases-U--update-stateMarktablesascrashedifyoufindanyerrors-T,--read-onlyDon'tmarktableascheckedRepairoptions(Whenusing'-r'or'-o')-B,--backupMakeabackupofthe.MYDfileas'filename-time.BAK'--correct-checksumCorrectchecksuminformationfortable.-D,--data-file-length=#Maxlengthofdatafile(whenrecreatingdatafilewhenit'sfull)-e,--extend-checkTrytorecovereverypossiblerowfromthedatafileNormallythiswillalsofindalotofgarbagerows;Don'tusethisoptionifyouarenottotallydesperate.-f,--forceOverwriteoldtemporaryfiles.-k,--keys-used=#TellMyISAMtoupdateonlysomespecifickeys.#isabitmaskofwhichkeystouse.Thiscanbeusedtogetfasterinserts!-r,--recoverCanfixalmostanythingexceptuniquekeysthataren'tunique.-n,--sort-recoverForcesrecoveringwithsortingevenifthetemporaryfilewouldbeverybig.-p,--parallel-recoverUsesthesametechniqueas'-r'and'-n',butcreatesallthekeysinparallel,indifferentthreads.THISISALPHACODE.USEATYOUROWNRISK!-o,--safe-recoverUsesoldrecoverymethod;Slowerthan'-r'butcanhandleacoupleofcaseswhere'-r'reportsthatitcan'tfixthedatafile.--character-sets-dir=...Directorywherecharactersetsare--set-character-set=nameChangethecharactersetusedbytheindex-q,--quickFasterrepairbynotmodifyingthedatafile.Onecangiveasecond'-q'toforcemyisamchktomodifytheoriginaldatafileincaseofduplicatekeys-u,--unpackUnpackfilepackedwithmyisampack.Otheractions:-a,--analyzeAnalyzedistributionofkeys.WillmakesomejoinsinMySQLfaster.Youcancheckthecalculateddistributionbyusing'--description--verbosetable_name'.-d,--descriptionPrintssomeinformationabouttable.-A,--set-auto-increment[=value]Forceauto_incrementtostartatthisorhighervalueIfnovalueisgiven,thensetsthenextauto_incrementvaluetothehighestusedvaluefortheautokey+1.-S,--sort-indexSortindexblocks.Thisspeedsup'read-next'inapplications-R,--sort-records=#Sortrecordsaccordingtoanindex.ThismakesyourdatamuchmorelocalizedandmayspeedupthingsC:\mysql\bin>myisamchkc:\mysql\data\hw_enterprice\function_products.frmmyisamchk:error:'c:\mysql\data\hw_enterprice\function_products.frm'isnotaMyISAM-tableC:\mysql\bin>myisamchkc:\mysql\data\hw_enterprice\function_products.myiCheckingMyISAMfile:c:\mysql\data\hw_enterprice\function_products.myiDatarecords:85207Deletedblocks:39myisamchk:warning:Tableismarkedascrashedmyisamchk:warning:1clientsisusingorhasn'tclosedthetableproperly-checkfile-size-checkkeydelete-chain-checkrecorddelete-chainmyisamchk:error:recorddelete-link-chaincorrupted-checkindexreference-checkdatarecordreferencesindex:1-checkdatarecordreferencesindex:2-checkdatarecordreferencesindex:3-checkrecordlinksmyisamchk:error:Wrongbytesec:0-195-171atlinkstart:841908MyISAM-table'c:\mysql\data\hw_enterprice\function_products.myi'iscorruptedFixitusingswitch"-r"or"-o"

  继续进行操作:

  C:\mysql\bin>myisamchk--recover--quickc:\mysql\data\hw_enterprice\function_products.myi-checkkeydelete-chain-checkrecorddelete-chainmyisamchk:error:recorddelete-link-chaincorruptedmyisamchk:error:Quick-recoveraborted;Runrecoverywithoutswitch'q'UpdatingMyISAMfile:c:\mysql\data\hw_enterprice\function_products.myiMyISAM-table'c:\mysql\data\hw_enterprice\function_products.myi'isnotfixedbecauseoferrorsTryfixingitbyusingthe--safe-recover(-o)orthe--force(-f)option

  系统提示我使用--safe-recover(-o)orthe--force(-f)option进行修复操作,于是

  C:\mysql\bin>myisamchk--safe-recoverc:\mysql\data\hw_enterprice\function_products.myi-recovering(withkeycache)MyISAM-table'c:\mysql\data\hw_enterprice\function_products.myi'Datarecords:85207Wrongbytesec:0-195-171at841908;SkippedDatarecords:85215

  MySQL数据库.frm文件、.MYD文件和.MYI文件怎么修复

  将修复后的物理文件复制到mysql\data下之后,通过phpMyAdmin进行访问,OK正常!

  本次数据修复操作成功,数据已被正常恢复,总计85215条记录,其中恢复数据共计85207条。

  总结本次经验及查找资料,如下:

  当你试图修复一个被破坏的表的问题时,有三种修复类型。如果你得到一个错误信息指出一个临时文件不能建立,删除信息所指出的文件并再试一次--这通常是上一次修复操作遗留下来的。

  这三种修复方法如下所示:

  %myisamchk--recover--quick/path/to/tblName%myisamchk--recover/path/to/tblName%myisamchk--safe-recover/path/to/tblName

  第一种是最快的,用来修复最普通的问题;而最后一种是最慢的,用来修复一些其它方法所不能修复的问题。

  检查和修复MySQL数据文件

  如果上面的方法无法修复一个被损坏的表,在你放弃之前,你还可以试试下面这两个技巧:

  如果你怀疑表的索引文件(*.MYI)发生了不可修复的错误,甚至是丢失了这个文件,你可以使用数据文件(*.MYD)和数据格式文件(*.frm)重新生成它。首先制作一个数据文件(tblName.MYD)的拷贝。重启你的MySQL服务并连接到这个服务上,使用下面的命令删除表的内容:mysql>DELETEFROMtblName;

  在删除表的内容的同时,会建立一个新的索引文件。退出登录并重新关闭服务,然后用你刚才保存的数据文件(tblName.MYD)覆盖新的(空)数据文件。最后,使用myisamchk执行标准的修复(上面的第二种方法),根据表的数据的内容和表的格式文件重新生成索引数据。

  如果你的表的格式文件(tblName.frm)丢失了或者是发生了不可修复的错误,但是你清楚如何使用相应的CREATETABLE语句来重新生成这张表,你可以重新生成一个新的.frm文件并和你的数据文件和索引文件(如果索引文件有问题,使用上面的方法重建一个新的)一起使用。首先制作一个数据和索引文件的拷贝,然后删除原来的文件(删除数据目录下有关这个表的所有记录)。

  启动MySQL服务并使用当初的CREATETABLE文件建立一个新的表。新的.frm文件应该可以正常工作了,但是最好你还是执行一下标准的修复(上面的第二种方法)。

关于MySQL数据库中怎么修复.frm文件、.MYD文件和.MYI文件就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI