国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL myisamchk修復正在使用,無法訪問數據表

2024-07-24 12:37:41
字體:
來源:轉載
供稿:網友

昨天由于機房掉電自己的mysql數據庫中大量表都出現了無法訪問或正使用的情況,后來查了可以使用mysql myisamchk命令進行修復,下面我來介紹一下.

Posted on December 31, 2009 by axl MyISAM是MySQL的預設storage engine. MyISAM table很容易爛掉(corrupted)。

此文章將教你如何檢查/修復這些爛掉的MyISAM tables.

每次你在MySQL DB 制造一個 table,將會在檔案系統上同時制造出*.frm、*.MYD,跟*.MYI等三種格式的檔案.

*.frm = 用來儲存資料表格式(file to store table format)

*.MYD(MyData) = 用來儲存資料(file to store data)

*.MYI(MyIndex) =用來儲存索引(file to store index)

如何檢查DB?哪個table 需要修復,用root 執行以下指令,假設要檢查DB1下的各個table,代碼如下:

#myisamchk /var/lib/mysql/DB1/*.MYI >> /tmp/myisamchk.log

螢幕輸出中,如果發現以下字樣,該資料表就應修復.

  1. myisamchk: error: Keypointers and record positions doesn’t match 
  2. MyISAM-table ‘/var/lib/mysql/DB1/news_post_comment.MYI’ is corrupted 
  3. Fix it using switch “-r” or “-o” 
  4. myisamchk: warning: 1 client is using or hasn’t closed the table properly 
  5. MyISAM-table ‘/var/lib/mysql/DB1/news_post.MYI’ is usable but should be fixed 
  6. myisamchk: warning: 1 client is using or hasn’t closed the table properly 
  7. MyISAM-table ‘/var/lib/mysql/DB1/news_post_push_log.MYI’ is usable but should be fixed 

Redirect出來的檔案中會顯示更多資訊,代碼如下:

  1. Checking MyISAM file: /var/lib/mysql/DB1/yam_bbauth.MYI 
  2. Data records: 14 Deleted blocks: 0 
  3. check file-size 
  4. check record delete-chain 
  5. check key delete-chain 
  6. check index reference 
  7. check data record references index: 1 
  8. check record links 

如何利用myisamchk修復爛掉的tables,找出爛掉的table之后,用以下指令修復,代碼如下:

  1.  #myisamchk –r /var/lib/mysql/DB1/news_post_comment.MYI  
  2. - recovering (with sort) MyISAM-table ‘/var/lib/mysql/DB1/news_post_comment.MYI 
  3. Data records: 1 
  4. - Fixing index 1 

如果table正被某個application使用,你可能會看到,clients are using or haven’t closed the table properly.

所以建議修復前將mysqld關掉或用FLUSH TABLES鎖住TABLES,防止修復時有application對DB TABLE做更動.

如何讓檢查跟修復同時進行,代碼如下:

  1.  #myisamchk --silent --force --fast --update-state /var/lib/mysql/DB1/*.MYI  
  2. myisamchk: MyISAM file /var/lib/mysql/DB1/groups.MYI 
  3. myisamchk: warning: 1 client is using or hasn’t closed the table properly 
  4. myisamchk: MyISAM file /var/lib/mysql/DB1/profiles.MYI 
  5. myisamchk: warning: 1 client is using or hasn’t closed the table properly 
  6. --options 的意義如下: 
  7. • s, –silent option: Prints only errors. You can use two -s to make myisamchk very silent. 
  8. • -f, –force option: Restart myisamchk automatically with repair option -r, if there are any errors in the table
  9. • -F, –fast optionCheck only tables that haven’t been closed properly. 
  10. • -U –update-state option: Marks tables as crashed, when it finds any error. 

修復時手動分配記憶體給龐大的DB,龐大的table,修復需要很長的時間,修復時可以手動增加記憶體參數,代碼如下:

  1. # myisamchk --silent --force --fast --update-state --key_buffer_size=512M --sort_buffer_size=512M  
  2. -read_buffer_size=4M --write_buffer_size=4M /var/lib/mysql/DB1/*.MYI  

用myisamchk 獲取table資訊,代碼如下:

  1. #myisamchk -dvv profiles.MYI  
  2. MyISAM file: profiles.MYI 
  3. Record format: Packed 
  4. Character set: latin1_swedish_ci (8) 
  5. File-version: 1 
  6. Creation time: 2007-08-16 18:46:59 
  7. Status: open,changed,analyzed,optimized keys,sorted index pages 
  8. Auto increment key: 1 Last value: 88 
  9. Data records: 88 Deleted blocks: 0 
  10. Datafile parts: 118 Deleted data: 0 
  11. Datafile pointer (bytes): 4 Keyfile pointer (bytes): 4 
  12. Datafile length: 6292 Keyfile length: 6144 
  13. Max datafile length: 4294967294 Max keyfile length: 4398046510079 
  14. Recordlength: 2124 
  15. table description: 
  16. Key Start Len Index Type Rec/key Root Blocksize 
  17. 1 2 3 unique int24 1 1024 1024 
  18. 2 5 765 unique char packed stripped 1 2048 4096 
  19. Field Start Length Nullpos Nullbit Type 
  20. 1 1 1 
  21. 2 2 3 no zeros 
  22. 3 5 765 no endspace 

最后一招:#myisamchk --help,MySQL 使用 myisamchk 修復 *.MYI 時,出現下述訊息:

  1. myisamchk: Disk is full writing '/tmp/ST3lJjsW' (Errcode: 28). Waiting for someone to free space... (Expect up to 60 secs delay for server to c ontinue after freeing disk space
  2. myisamchk: Retry in 60 secs. Message reprinted in 600 secs 

解法1:

■由訊息可以知道, myisamchk 需要使用到 /tmp,/tmp 容量不夠就會出現此訊息,所以如果 /tmp 可以清出空間,清出 /tmp 的空間就可以解決了,但是如果 /tmp 本身切的就不夠大,可以使用下述解法.

解法2:此解法取自: free disk space error using myisamchk

■myisamchk -rq --sort_buffer_size=256M --key_buffer_size=256M --read_buffer_size=32M --write_buffer_size=32M --sort-index --analyze --tmpdir=/more-disk-space-directory/ /var/lib/mysql/database/T1.MYI

■?: 修改 --tmpdir=/more-disk-space-directory/ 指定到空間比較大的地方去即可.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 湟源县| 莲花县| 柳江县| 霍城县| 循化| 什邡市| 讷河市| 油尖旺区| 阿拉善左旗| 霍林郭勒市| 五常市| 遂平县| 安陆市| 河津市| 工布江达县| 堆龙德庆县| 马关县| 新乡市| 马尔康县| 赤壁市| 怀集县| 宁河县| 全南县| 辰溪县| 沐川县| 乌兰县| 通江县| 韶关市| 卓资县| 钦州市| 邹城市| 分宜县| 叶城县| 珠海市| 云林县| 郓城县| 班玛县| 苗栗市| 开远市| 获嘉县| 彩票|