溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MySQL數(shù)據(jù)庫中怎么修復.frm文件、.MYD文件和.MYI文件

發(fā)布時間:2021-07-24 17:20:19 來源:億速云 閱讀:607 作者:Leah 欄目:數(shù)據(jù)庫

這篇文章給大家介紹MySQL數(shù)據(jù)庫中怎么修復.frm文件、.MYD文件和.MYI文件,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

  MySQL數(shù)據(jù)庫.frm文件、.MYD文件和.MYI文件怎么修復

  要檢查一個表的錯誤,只需要運行myisamchk(在MySQL的bin目錄下)并提供文件的位置和表名,或者是表的索引文件名:

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

  上面的兩個命令都可以執(zhí)行對指定表的檢查。要檢查數(shù)據(jù)庫中所有的表,可以使用通配符:

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

  如果不帶任何選項,myisamchk將對表文件執(zhí)行普通的檢查。如果你對一個表有懷疑,但是普通的檢查不能發(fā)現(xiàn)任何錯誤,你可以執(zhí)行更徹底的檢查(但是也更慢!),這需要使用--extend-check選項:

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

  對錯誤的檢查是沒有破壞性的,這意味著你不必擔心執(zhí)行對你的數(shù)據(jù)文件的檢查會使已經(jīng)存在的問題變得更糟。另一方面,修復選項,雖然通常也是安全的,但是它對你的數(shù)據(jù)文件的更改是無法撤消的。因為這個原因,我們強烈推薦你試圖修復一個被破壞的表文件時首先做個備份,并確保在制作這個備份之前你的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"

  繼續(xù)進行操作:

  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

  系統(tǒng)提示我使用--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數(shù)據(jù)庫.frm文件、.MYD文件和.MYI文件怎么修復

  將修復后的物理文件復制到mysql\data下之后,通過phpMyAdmin進行訪問,OK正常!

  本次數(shù)據(jù)修復操作成功,數(shù)據(jù)已被正?;謴?,總計85215條記錄,其中恢復數(shù)據(jù)共計85207條。

  總結本次經(jīng)驗及查找資料,如下:

  當你試圖修復一個被破壞的表的問題時,有三種修復類型。如果你得到一個錯誤信息指出一個臨時文件不能建立,刪除信息所指出的文件并再試一次--這通常是上一次修復操作遺留下來的。

  這三種修復方法如下所示:

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

  第一種是最快的,用來修復最普通的問題;而最后一種是最慢的,用來修復一些其它方法所不能修復的問題。

  檢查和修復MySQL數(shù)據(jù)文件

  如果上面的方法無法修復一個被損壞的表,在你放棄之前,你還可以試試下面這兩個技巧:

  如果你懷疑表的索引文件(*.MYI)發(fā)生了不可修復的錯誤,甚至是丟失了這個文件,你可以使用數(shù)據(jù)文件(*.MYD)和數(shù)據(jù)格式文件(*.frm)重新生成它。首先制作一個數(shù)據(jù)文件(tblName.MYD)的拷貝。重啟你的MySQL服務并連接到這個服務上,使用下面的命令刪除表的內容:mysql>DELETEFROMtblName;

  在刪除表的內容的同時,會建立一個新的索引文件。退出登錄并重新關閉服務,然后用你剛才保存的數(shù)據(jù)文件(tblName.MYD)覆蓋新的(空)數(shù)據(jù)文件。最后,使用myisamchk執(zhí)行標準的修復(上面的第二種方法),根據(jù)表的數(shù)據(jù)的內容和表的格式文件重新生成索引數(shù)據(jù)。

  如果你的表的格式文件(tblName.frm)丟失了或者是發(fā)生了不可修復的錯誤,但是你清楚如何使用相應的CREATETABLE語句來重新生成這張表,你可以重新生成一個新的.frm文件并和你的數(shù)據(jù)文件和索引文件(如果索引文件有問題,使用上面的方法重建一個新的)一起使用。首先制作一個數(shù)據(jù)和索引文件的拷貝,然后刪除原來的文件(刪除數(shù)據(jù)目錄下有關這個表的所有記錄)。

  啟動MySQL服務并使用當初的CREATETABLE文件建立一個新的表。新的.frm文件應該可以正常工作了,但是最好你還是執(zhí)行一下標準的修復(上面的第二種方法)。

關于MySQL數(shù)據(jù)庫中怎么修復.frm文件、.MYD文件和.MYI文件就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI