MYISAM索引文件损坏的修复方法
2008-12-16 13:05:03 来源:WEB开发网 闂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂寸绾惧綊鏌熼梻瀵割槮缁炬儳缍婇弻鐔兼⒒鐎靛壊妲紒鐐劤缂嶅﹪寮婚悢鍏尖拻閻庨潧澹婂Σ顔剧磼閹冣挃闁硅櫕鎹囬垾鏃堝礃椤忎礁浜鹃柨婵嗙凹缁ㄧ粯銇勯幒瀣仾闁靛洤瀚伴獮鍥敍濮f寧鎹囬弻鐔哥瑹閸喖顬堝銈庡亝缁挸鐣烽崡鐐嶆棃鍩€椤掑嫮宓佸┑鐘插绾句粙鏌涚仦鎹愬闁逞屽墰閹虫捇锝炲┑瀣╅柍杞拌兌閻ゅ懐绱撴担鍓插剱妞ゆ垶鐟╁畷銉р偓锝庡枟閻撴洘銇勯幇闈涗簼缂佽埖姘ㄧ槐鎾诲礃閳哄倻顦板┑顔硷工椤嘲鐣烽幒鎴旀瀻闁规惌鍘借ⅵ濠电姷鏁告慨顓㈠磻閹剧粯鈷戞い鎺嗗亾缂佸鏁婚獮鍡涙倷閸濆嫮顔愬┑鐑囩秵閸撴瑦淇婇懖鈺冪<闁归偊鍙庡▓婊堟煛鐏炵硶鍋撻幇浣告倯闁硅偐琛ラ埀顒冨皺閺佹牕鈹戦悙鏉戠仸闁圭ǹ鎽滅划鏃堟偨缁嬭锕傛煕閺囥劌鐏犻柛鎰ㄥ亾婵$偑鍊栭崝锕€顭块埀顒佺箾瀹€濠侀偗婵﹨娅g槐鎺懳熺拠鑼舵暱闂備胶枪濞寸兘寮拠宸殨濠电姵纰嶉弲鎻掝熆鐠虹尨宸ョ€规挸妫濆铏圭磼濡搫顫嶇紓浣风劍閹稿啿鐣烽幋锕€绠婚悹鍥у级瀹撳秴顪冮妶鍡樺鞍缂佸鍨剁粋宥夋倷椤掍礁寮垮┑鈽嗗灣閸樠勭妤e啯鍊垫慨妯煎亾鐎氾拷

使用MYISAM存储引擎,当创建一个表时,会出现三个文件:数据文件MYD,索引文件MYI,格式文件frm。当索引文件损坏时或者丢失时,可以用如下的方法进行修复。下面是实验过程。 [mysql@testapp74 notify]$ mv message_ignore.MYI message_ignore.MYI.bak
[mysql@testapp74 notify]$
[mysql@testapp74 notify]$ mysqld_safe &
[1] 26267
[mysql@testapp74 notify]$ 080630 14:19:03 mysqld_safe Logging to '/usr/mysql_data/log/alert.log'.
080630 14:19:03 mysqld_safe Starting mysqld daemon with databases from /usr/mysql_data/data
[mysql@testapp74 notify]$
[mysql@testapp74 notify]$
[mysql@testapp74 notify]$
[mysql@testapp74 notify]$ vi /usr/mysql_data/log/alert.log
080630 14:18:14 [Note] /usr/sbin/mysqld: Normal shutdown
080630 14:18:14 [Note] Event Scheduler: Purging the queue. 0 events
080630 14:18:16 InnoDB: Starting shutdown...
080630 14:18:19 InnoDB: Shutdown completed; log sequence number 162 783173592
080630 14:18:19 [Note] /usr/sbin/mysqld: Shutdown complete
080630 14:18:19 mysqld_safe mysqld from pid file /usr/mysql_data/data/testapp74.pid ended
080630 14:19:03 mysqld_safe Starting mysqld daemon with databases from /usr/mysql_data/data
080630 14:19:03 InnoDB: Started; log sequence number 162 783173592
080630 14:19:03 [Note] Event Scheduler: Loaded 0 events
080630 14:19:03 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.1.23-rc-community' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Edition (GPL)
从上面可以看出,当一个表出现问题,mysql的警告日志并没有任何的错误出现。 [mysql@testapp74 notify]$ mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.1.23-rc-community MySQL Community Edition (GPL)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> use notify
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
mysql>
mysql>
mysql>
mysql> select * from message_ignore limit 1; --当查询表时,会报错
ERROR 1017 (HY000): Can't find file: 'message_ignore' (errno: 2)
mysql> check table message_ignore;
+-----------------------+-------+----------+----------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------------+-------+----------+----------------------------------------------+
| notify.message_ignore | check | Error | Can't find file: 'message_ignore' (errno: 2) |
| notify.message_ignore | check | error | Corrupt |
+-----------------------+-------+----------+----------------------------------------------+
2 rows in set (0.03 sec)
mysql>
mysql> repair table message_ignore;
+-----------------------+--------+----------+----------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-----------------------+--------+----------+----------------------------------------------+
| notify.message_ignore | repair | Error | Can't find file: 'message_ignore' (errno: 2) |
| notify.message_ignore | repair | error | Corrupt |
+-----------------------+--------+----------+----------------------------------------------+
2 rows in set (0.00 sec)
更多精彩
赞助商链接