October 20, 2006

mysql 修復筆記

近日實驗室的主機 mysql 掛了
嘗試使用 /etc/init.d/mysql start 來找錯誤
發現只會. . . . . . . . . failed
且 /var/log/mysql.err 跟 mysql.log 竟然都是空的

放狗搜了之後
就使用
mysqld 來啟動
好在這招看的到錯誤訊息
結果是[ERROR] mysql I/O error reading the header from the binary log
看來只好把 /var/log/mysql/mysql-bin.index 清空
再來啟動 mysqld
看來就解決了
不過

這次就說有一堆 TABLE 損毀
[ERROR] mysqld: Table './mt/mt_tbping' is marked as crashed and should be repaired
這種訊息一堆啊!
真是Orz
再次放狗搜
發現有指令可以修復(之前有用過 phpmyadmin 來診斷修復 不過今天卻一直找不到該功能!?)
只好使用相關指令
先停止mysql 後 cd /var/lib/mysql
再 myisamchk -a "TABLE_NAME" 診斷錯誤類型
=================================================
wshlab2:/var/lib/mysql# myisamchk -a apacheacct/accounting
Checking MyISAM file: apacheacct/accounting
Data records: 142266 Deleted blocks: 0
myisamchk: warning: Table is marked as crashed
myisamchk: warning: 1 client is using or hasn't closed the table properly
- check file-size
myisamchk: warning: Size of datafile is: 5575772 Should be: 5575732
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check record links
myisamchk: error: Wrong bytesec: 0-0-0 at linkstart: 5575732
MyISAM-table 'apacheacct/accounting' is corrupted
Fix it using switch "-r" or "-o"
=================================================
再依照其建議修復資料表
wshlab2:/var/lib/mysql#myisamchk -r apacheacct/accounting
- recovering (with sort) MyISAM-table 'apacheacct/accounting'
Data records: 142266
- Fixing index 1
Wrong bytesec: 0- 0- 0 at 5575732; Skipped
就美滿的收尾了
好家在!還有的修不然就要重新安裝 mysql 了...

由 k 發表於 04:12 PM | 迴響 (0)