Ç°¼¸ÌìÒòΪMySQLÊý¾Ý¿â²¿·ÖÊý¾ÝËð»µÔÒò£¬ÎÒ³¢ÊÔÁËÏ»ָ´Êý¾Ý£¬Ö®ºóÕûÀíÒÔÏÂÎĵµ£¬¹©¸÷λ²Î¿¼,ÒÔ±¸¸÷λͬÊÂÒÔºóÈçÓÐÀàËÆÎÊÌ⣬¿ÉÒÔÉÙ×ßЩÍä·,¾¡¿ì½â¾öÎÊÌâ¡£
»·¾³£ºWindows2003
Êý¾Ý¿â:MySQL
Ëð»µÊý¾ÝÎļþÃû:function_products
½«Êý¾Ý¿âÄÚÈÝÎïÀíÎļþÖ±½Óµ¼Èëµ½mysql\dataÏ£¬Ã¿Ö»±í¸÷3¸öÎļþ£¬ÒÀ´Î·Ö±ðΪ£º.frm .myd .myi¡£Ê×ÏÈÎÒµÚÒ»Ïëµ½µÄÊÇÈ¥ÍøÉÏËÑË÷£¬Ñ°ÕÒÀàËƵŤ¾ß£¬ÊÔͼͨ¹ý¹¤¾ßÀ´»Ö¸´ÒÑË𻵵ÄÎļþ£¬ÓÚÊÇÎÒÔÚgoogleÉϲéÕÒ£¬ÕÒµ½Ò»¿îÃûΪmysqlrecoveryµÄ¹¤¾ß£¬°²×°ºóÎÒÓÃÆä½øÐлָ´£¬Ö»¿ÉϧЧ¹ûÌ«²»ÀíÏ룬¼¸Ê®MB´óµÄÊý¾ÝÎļþ£¬»Ö¸´Ö®ºóËüÌáʾÎÒ¾¹È»Ö»Óм¸Ê®KB¡£ÎÒÓÖÏëµ½ÁËMySQLÏÂÓ¦ÓÐ×Ô¼º±¾ÉíµÄÐÞ¸´³ÌÐòµÈ£¬ÓÚÊÇÏëͨ¹ýÆäÀ´½øÐлָ´£¬ÐÄÏëÓ¦²»»áÌ«²î¾¢°É£¬ÔÚÍøÉϲéÕÒÁË×ÊÁÏ£¬Ìáʾ£ºÓÉÓÚÁÙʱ¶Ïµç£¬Ê¹ÓÃkill -9ÖÐÖ¹MySQL·þÎñ½ø³Ì£¬»òÕßÊÇMySQLÕýÔÚ¸ßËÙÔËתʱ½øÐÐÇ¿ÖƱ¸·Ý²Ù×÷ʱµÈ£¬ËùÓеÄÕâЩ¶¼¿ÉÄÜ»á»Ù»µMySQLµÄÊý¾ÝÎļþ¡£Èç¹ûÔÚ±»¸ÉÈÅʱ£¬·þÎñÕýÔڸıäÎļþ£¬Îļþ¿ÉÄÜ»áÁôÏ´íÎóµÄ»ò²»Ò»ÖµÄ״̬¡£ÒòΪÕâÑùµÄ»Ù»µÓÐʱÊDz»ÈÝÒ×±»·¢Ïֵģ¬µ±Äã·¢ÏÖÕâ¸ö´íÎóʱ¿ÉÄÜÊǺܾÃÒÔºóµÄÊÂÁË¡£
ÓÚÊÇ£¬µ±Äã·¢ÏÖÕâ¸öÎÊÌâʱ£¬Ò²ÐíËùÓеı¸·Ý¶¼ÓÐͬÑùµÄ´íÎó¡£ÎÒÏëÎÒÏÖÔÚÅöµ½µÄÎÊÌâ¿ÉÄÜÊÇÕâ¸öÎÊÌ⣬ÒòΪ±¸·ÝµÄÊý¾ÝÒ²ÊÇÓв¿·ÖË𻵵ÄÊý¾Ý£¬ËùÒÔµ¼Ö²»ÄÜÍêÈ«ÔËÐУ¬ Òâʶµ½myisamchk³ÌÐò¶ÔÓÃÀ´¼ì²éºÍÐ޸ĵÄMySQLÊý¾ÝÎļþµÄ·ÃÎÊÓ¦¸ÃÊÇΨһµÄ¡£Èç¹ûMySQL·þÎñÕýÔÚʹÓÃijһÎļþ£¬²¢¶ÔmyisamchkÕýÔÚ¼ì²éµÄÎļþ½øÐÐÐ޸ģ¬myisamchk»áÎóÒÔΪ·¢ÉúÁË´íÎ󣬲¢»áÊÔͼ½øÐÐÐÞ¸´--Õ⽫µ¼ÖÂMySQL·þÎñµÄ±ÀÀ££¡ÕâÑù£¬Òª±ÜÃâÕâÖÖÇé¿öµÄ·¢Éú£¬Í¨³£ÎÒÃÇÐèÒªÔÚ¹¤×÷ʱ¹Ø±ÕMySQL·þÎñ¡£×÷ΪѡÔñ£¬ÄãÒ²¿ÉÒÔÔÝʱ¹Ø±Õ·þÎñÒÔÖÆ×÷Ò»¸öÎļþµÄ¿½±´£¬È»ºóÔÚÕâ¸ö¿½±´ÉϹ¤×÷¡£µ±Äã×öÍêÁËÒÔºó£¬ÖØйرշþÎñ²¢Ê¹ÓÃеÄÎļþÈ¡´úÔÀ´µÄÎļþ(Ò²ÐíÄ㻹ÐèҪʹÓÃÆÚ¼äµÄ±ä¸üÈÕÖ¾)¡£
MySQLÊý¾ÝĿ¼²»ÊÇÌ«ÄÑÀí½âµÄ¡£Ã¿Ò»¸öÊý¾Ý¿â¶ÔÓ¦Ò»¸ö×ÓĿ¼£¬Ã¿¸ö×ÓĿ¼Öаüº¬Á˶ÔÓ¦ÓÚÕâ¸öÊý¾Ý¿âÖеÄÊý¾Ý±íµÄÎļþ¡£Ã¿Ò»¸öÊý¾Ý±í¶ÔÓ¦Èý¸öÎļþ£¬ËüÃǺͱíÃûÏàͬ£¬µ«ÊǾßÓв»Í¬µÄÀ©Õ¹Ãû¡£tblname.frmÎļþÊDZíµÄ¶¨Ò壬Ëü±£´æÁ˱íÖаüº¬µÄÊý¾ÝÁеÄÄÚÈݺÍÀàÐÍ¡£tblname.mydÎļþ°üº¬Á˱íÖеÄÊý¾Ý¡£tblname.myiÎļþ°üº¬Á˱íµÄË÷Òý(ÀýÈ磬Ëü¿ÉÄÜ°üº¬lookup±íÒÔ°ïÖúÌá¸ß¶Ô±íµÄÖ÷¼üÁеIJéѯ)¡£ Òª¼ì²éÒ»¸ö±íµÄ´íÎó£¬Ö»ÐèÒªÔËÐÐmyisamchk(ÔÚMySQLµÄbinĿ¼ÏÂ)²¢ÌṩÎļþµÄλÖúͱíÃû£¬»òÕßÊDZíµÄË÷ÒýÎļþÃû£º
% myisamchk /usr/local/mysql/var/dbname/tblname
% myisamchk /usr/local/mysql/var/dbname/tblname.myi
ÉÏÃæµÄÁ½¸öÃüÁ¿ÉÒÔÖ´ÐжÔÖ¸¶¨±íµÄ¼ì²é¡£Òª¼ì²éÊý¾Ý¿âÖÐËùÓÐµÄ±í£¬¿ÉÒÔʹÓÃͨÅä·û£º
% myisamchk /usr/local/mysql/var/dbname/*.myi
Òª¼ì²éËùÓÐÊý¾Ý¿âÖеÄËùÓÐ±í£¬¿ÉÒÔʹÓÃÁ½¸öͨÅä·û£º
% myisamchk /usr/local/mysql/var/*/*.myi
Èç¹û²»´øÈκÎÑ¡Ïmyisamchk½«¶Ô±íÎļþÖ´ÐÐÆÕͨµÄ¼ì²é¡£Èç¹ûÄã¶ÔÒ»¸ö±íÓл³ÒÉ£¬µ«ÊÇÆÕͨµÄ¼ì²é²»ÄÜ·¢ÏÖÈκδíÎó£¬Äã¿ÉÒÔÖ´Ðиü³¹µ×µÄ¼ì²é(µ«ÊÇÒ²¸üÂý£¡)£¬ÕâÐèҪʹÓÃ--extend-checkÑ¡Ï
% myisamchk --extend-check /path/to/tblname
¶Ô´íÎóµÄ¼ì²éÊÇûÓÐÆÆ»µÐԵģ¬ÕâÒâζ×ÅÄã²»±Øµ£ÐÄÖ´ÐжÔÄãµÄÊý¾ÝÎļþµÄ¼ì²é»áʹÒѾ´æÔÚµÄÎÊÌâ±äµÃ¸üÔã¡£ÁíÒ»·½Ã棬ÐÞ¸´Ñ¡ÏËäȻͨ³£Ò²ÊÇ°²È«µÄ£¬µ«ÊÇËü¶ÔÄãµÄÊý¾ÝÎļþµÄ¸ü¸ÄÊÇÎÞ·¨³·ÏûµÄ¡£ÒòΪÕâ¸öÔÒò£¬ÎÒÃÇÇ¿ÁÒÍƼöÄãÊÔͼÐÞ¸´Ò»¸ö±»ÆÆ»µµÄ±íÎļþʱÊ×ÏÈ×ö¸ö±¸·Ý£¬²¢È·±£ÔÚÖÆ×÷Õâ¸ö±¸·Ý֮ǰÄãµÄMySQL·þÎñÊǹرյġ£
ÎÒÔÚWin2003ÏÂͨ¹ýÃüÁîÌáʾ·û£¬ÊäÈ룺
×¢£º´ËΪ¼Ç¼ÎÒµ±Ê±²Ù×÷µÄÈ«²¿¹ý³Ì
d:\documents and settings\administrator>c:
c:\>cd MySQL
c:\mysql>cd data
c:\mysql\data>cd hw_enterprice
c:\mysql\data\hw_enterprice>myisamchk function_products.frm
'myisamchk' ²»ÊÇÄÚ²¿»òÍⲿÃüÁҲ²»ÊÇ¿ÉÔËÐеijÌÐò»òÅú´¦ÀíÎļþ¡£
c:\mysql\data\hw_enterprice>cd\
c:\>cd mysql
c:\mysql>cd bin
×¢£º²é¿´myisamchkµÄ°ïÖúÐÅÏ¢
c:\mysql\bin>myisamchk
myisamchk ver 2.6 for win95/win98 at i32
by monty, for your professional use
this software comes with no warranty: see the public for details.
description, check and repair of isam tables.
used without options all tables on the command will be checked for errors
usage: myisamchk [options] tables[.myi]
global options:
-#, --debug=... output debug log. often this is 'd:t:o,filename'
-?, --help display this help and exit.
-o, --set-variable var=option
change the value of a variable. please note that
this option is deprecated; you can set variables
directly with '--variable-name=value'.
-t, --tmpdir=path path for temporary files
-s, --silent only print errors. one can use two -s to make
myisamchk very silent
-v, --verbose print more information. this can be used with
--description and --check. use many -v for more verbosity!
-v, --version print version and exit.
-w, --wait wait if table is locked.
check options (check is the default action for myisamchk):
-c, --check check table for errors
-e, --extend-check check the table very throughly. only use this in
extreme cases as myisamchk should normally be able to
find out if the table is ok even without this switch
-f, --fast check only tables that haven't been closed properly
-c, --check-only-changed
check only tables that have changed since last check
-f, --force restart with '-r' if there are any errors in the table.
states will be updated as with '--update-state'
-i, --information print statistics information about table that is checked
-m, --medium-check faster than extend-check, but only finds 99.99% of
all errors. should be good enough for most cases
-u --update-state mark tables as crashed if you find any errors
-t, --read-only don't mark table as checked
repair options (when using '-r' or '-o')
-b, --backup make a backup of the .myd file as 'filename-time.bak'
--correct-checksum correct checksum information for table.
-d, --data-file-length=# max length of data file (when recreating data
file when it's full)
-e, --extend-check try to recover every possible row from the data file
normally this will also find a lot of garbage rows;
don't use this option if you are not totally desperate.
-f, --force overwrite old temporary files.
-k, --keys-used=# tell myisam to update only some specific keys. # is a
bit mask of which keys to use. this can be used to
get faster inserts!
-r, --recover can fix almost anything except unique keys that aren't
unique.
-n, --sort-recover forces recovering with sorting even if the temporary
file would be very big.
-p, --parallel-recover
uses the same technique as '-r' and '-n', but creates
all the keys in parallel, in different threads.
this is alpha code. use at your own risk!
-o, --safe-recover uses old recovery method; slower than '-r' but can
handle a couple of cases where '-r' reports that it
can't fix the data file.
--character-sets-dir=...
directory where character sets are
--set-character-set=name
change the character set used by the index
-q, --quick faster repair by not modifying the data file.
one can give a second '-q' to force myisamchk to
modify the original datafile in case of duplicate keys
-u, --unpack unpack file packed with myisampack.
other actions:
-a, --analyze analyze distribution of keys. will make some joins in
MySQL faster. you can check the calculated distribution
by using '--description --verbose table_name'.
-d, --description prints some information about table.
-a, --set-auto-increment[=value]
force auto_increment to start at this or higher value
if no value is given, then sets the next auto_increment
value to the highest used value for the auto key + 1.
-s, --sort-index sort index blocks. this speeds up 'read-next' in
applications
-r, --sort-records=#
sort records according to an index. this makes your
data much more localized and may speed up things
c:\mysql\bin>myisamchk c:\mysql\data\hw_enterprice\function_products.frm
myisamchk: error: 'c:\mysql\data\hw_enterprice\function_products.frm' is not a m
yisam-table
c:\mysql\bin>myisamchk c:\mysql\data\hw_enterprice\function_products.myi
checking myisam file: c:\mysql\data\hw_enterprice\function_products.myi
data records: 85207 deleted blocks: 39
myisamchk: warning: table is marked as crashed
myisamchk: warning: 1 clients is using or hasn't closed the table properly
- check file-size
- check key delete-chain
- check record delete-chain
myisamchk: error: record delete-link-chain corrupted
- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check record links
myisamchk: error: wrong bytesec: 0-195-171 at linkstart: 841908
myisam-table 'c:\MySQL\data\hw_enterprice\function_products.myi' is corrupted
fix it using switch "-r" or "-o"
¼ÌÐø½øÐвÙ×÷£º
c:\MySQL\bin>myisamchk --recover --quick c:\MySQL\data\hw_enterprice\function_p
roducts.myi
- check key delete-chain
- check record delete-chain
myisamchk: error: record delete-link-chain corrupted
myisamchk: error: quick-recover aborted; run recovery without switch 'q'
updating myisam file: c:\MySQL\data\hw_enterprice\function_products.myi
myisam-table 'c:\MySQL\data\hw_enterprice\function_products.myi' is not fixed be
cause of errors
try fixing it by using the --safe-recover (-o) or the --force (-f) option
ϵͳÌáʾÎÒʹÓÃ--safe-recover (-o) or the --force (-f) option½øÐÐÐÞ¸´²Ù×÷£¬ÓÚÊÇ
c:\MySQL\bin>myisamchk --safe-recover c:\MySQL\data\hw_enterprice\function_prod
ucts.myi
- recovering (with keycache) myisam-table 'c:\MySQL\data\hw_enterprice\function_
products.myi'
data records: 85207
wrong bytesec: 0-195-171 at 841908; skipped
data records: 85215
½«ÐÞ¸´ºóµÄÎïÀíÎļþ¸´ÖƵ½mysql\dataÏÂÖ®ºó£¬Í¨¹ýphpmyadmin½øÐзÃÎÊ£¬Õý³££¡±¾´ÎÊý¾ÝÐÞ¸´²Ù×÷³É¹¦£¬Êý¾ÝÒѱ»Õý³£»Ö¸´£¬×ܼÆ85215Ìõ¼Ç¼£¬ÆäÖлָ´Êý¾Ý¹²¼Æ85207Ìõ¡£
×ܽ᱾´Î¾Ñé¼°²éÕÒ×ÊÁÏ£¬ÈçÏ£º
µ±ÄãÊÔͼÐÞ¸´Ò»¸ö±»ÆÆ»µµÄ±íµÄÎÊÌâʱ£¬ÓÐÈýÖÖÐÞ¸´ÀàÐÍ¡£Èç¹ûÄãµÃµ½Ò»¸ö´íÎóÐÅÏ¢Ö¸³öÒ»¸öÁÙʱÎļþ²»Äܽ¨Á¢£¬É¾³ýÐÅÏ¢ËùÖ¸³öµÄÎļþ²¢ÔÙÊÔÒ»´Î--Õâͨ³£ÊÇÉÏÒ»´ÎÐÞ¸´²Ù×÷ÒÅÁôÏÂÀ´µÄ¡£
ÕâÈýÖÖÐÞ¸´·½·¨ÈçÏÂËùʾ£º
% myisamchk --recover --quick /path/to/tblname
% myisamchk --recover /path/to/tblname
% myisamchk --safe-recover /path/to/tblname
µÚÒ»ÖÖÊÇ×î¿ìµÄ£¬ÓÃÀ´ÐÞ¸´×îÆÕͨµÄÎÊÌ⣻¶ø×îºóÒ»ÖÖÊÇ×îÂýµÄ£¬ÓÃÀ´ÐÞ¸´Ò»Ð©ÆäËü·½·¨Ëù²»ÄÜÐÞ¸´µÄÎÊÌâ¡£
Èç¹ûÉÏÃæµÄ·½·¨ÎÞ·¨ÐÞ¸´Ò»¸ö±»Ëð»µµÄ±í£¬ÔÚÄã·ÅÆú֮ǰ£¬Ä㻹¿ÉÒÔÊÔÊÔÏÂÃæÕâÁ½¸ö¼¼ÇÉ£º
Èç¹ûÄ㻳ÒɱíµÄË÷ÒýÎļþ(*.myi)·¢ÉúÁ˲»¿ÉÐÞ¸´µÄ´íÎó£¬ÉõÖÁÊǶªÊ§ÁËÕâ¸öÎļþ£¬Äã¿ÉÒÔʹÓÃÊý¾ÝÎļþ(*.myd)ºÍÊý¾Ý¸ñʽÎļþ(*.frm)ÖØÐÂÉú³ÉËü¡£Ê×ÏÈÖÆ×÷Ò»¸öÊý¾ÝÎļþ(tblname.myd)µÄ¿½±´¡£ÖØÆôÄãµÄMySQL·þÎñ²¢Á¬½Óµ½Õâ¸ö·þÎñÉÏ£¬Ê¹ÓÃÏÂÃæµÄÃüÁîɾ³ý±íµÄÄÚÈÝ£º
MySQL> delete from tblname;
ÔÚɾ³ý±íµÄÄÚÈݵÄͬʱ£¬»á½¨Á¢Ò»¸öеÄË÷ÒýÎļþ¡£Í˳öµÇ¼²¢ÖØйرշþÎñ£¬È»ºóÓÃÄã¸Õ²Å±£´æµÄÊý¾ÝÎļþ(tblname.myd)¸²¸ÇеÄ(¿Õ)Êý¾ÝÎļþ¡£×îºó£¬Ê¹ÓÃmyisamchkÖ´Ðбê×¼µÄÐÞ¸´(ÉÏÃæµÄµÚ¶þÖÖ·½·¨)£¬¸ù¾Ý±íµÄÊý¾ÝµÄÄÚÈݺͱíµÄ¸ñʽÎļþÖØÐÂÉú³ÉË÷ÒýÊý¾Ý¡£
Èç¹ûÄãµÄ±íµÄ¸ñʽÎļþ(tblname.frm)¶ªÊ§ÁË»òÕßÊÇ·¢ÉúÁ˲»¿ÉÐÞ¸´µÄ´íÎ󣬵«ÊÇÄãÇå³þÈçºÎʹÓÃÏàÓ¦µÄcreate tableÓï¾äÀ´ÖØÐÂÉú³ÉÕâÕÅ±í£¬Äã¿ÉÒÔÖØÐÂÉú³ÉÒ»¸öеÄ.frmÎļþ²¢ºÍÄãµÄÊý¾ÝÎļþºÍË÷ÒýÎļþ(Èç¹ûË÷ÒýÎļþÓÐÎÊÌ⣬ʹÓÃÉÏÃæµÄ·½·¨Öؽ¨Ò»¸öеÄ)Ò»ÆðʹÓá£Ê×ÏÈÖÆ×÷Ò»¸öÊý¾ÝºÍË÷ÒýÎļþµÄ¿½±´£¬È»ºóɾ³ýÔÀ´µÄÎļþ(ɾ³ýÊý¾ÝĿ¼ÏÂÓйØÕâ¸ö±íµÄËùÓмǼ)¡£
Æô¶¯MySQL·þÎñ²¢Ê¹Óõ±³õµÄcreate tableÎļþ½¨Á¢Ò»¸öÐÂµÄ±í¡£ÐµÄ.frmÎļþÓ¦¸Ã¿ÉÒÔÕý³£¹¤×÷ÁË£¬µ«ÊÇ×îºÃÄ㻹ÊÇÖ´ÐÐһϱê×¼µÄÐÞ¸´(ÉÏÃæµÄµÚ¶þÖÖ·½·¨)¡£
Èç¹ûÓÐÀàËÆÎÊÌ⣬½¨Òé×Ô¼ºÏÈ·ÖÎöÎÊÌâ¸ùÔ´£¬²éÕÒ×ÊÁÏ£¬×Ô¼º¶¯ÊÖ½â¾ö£¬²»µ«¿ÉÒÔ¶àѧ¸ü¶à֪ʶ¼¼ÇÉ£¬¸üÖØÒªµÄÊÇ£¬×Ô¼ºÒ²ÔÚ½â¾öÎÊÌâµÄͬʱµÃµ½ÁË¿ìÀÖ¡£