解決MySQL Table '***' is marked as crashed and should be repaired問題

來源:互聯網
上載者:User

標籤:mysql

昨天后端程式在讀取資料庫資訊時候,日誌報相關資料表不能讀取和寫入資料,進入 MySQL資料庫發現 Table ‘./wordpress/wp_posts’ is marked as crashed and should be repaired 錯誤,因為qqtexas中有資料表被損壞了,所以讀取不了資料:

# mysql -u root -pEnter password:mysql> use qqtexas;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> select * from wp_posts;ERROR 145 (HY000): Table ‘./wordpress/wp_posts‘ is marked as crashed and should be repairedmysql> quit

方法一:

修複 MySQL 資料庫資料表問題可以由 mysqlcheck 來解決,先用 mysqlcheck 查看一下:

# mysqlcheck -u root -p qqtexasEnter password:

然後添加 --auto-repair 參數自動修複,最好修複前備份一下資料庫:

# mysqldump -u root -p qqtexas > qqtexas.sqlEnter password:# mysqlcheck -u root -p qqtexas --auto-repairEnter password:wordpress.wp_term_taxonomyerror    : Table upgrade required. Please do "REPAIR TABLE `wp_term_taxonomy`" or dump/reload to fix it!wordpress.wp_termserror    : Table upgrade required. Please do "REPAIR TABLE `wp_terms`" or dump/reload to fix it!wordpress.wp_usermetaerror    : Table upgrade required. Please do "REPAIR TABLE `wp_usermeta`" or dump/reload to fix it!wordpress.wp_userserror    : Table upgrade required. Please do "REPAIR TABLE `wp_users`" or dump/reload to fix it!Repairing tablesqqtexas.wp_commentmeta                       OKqqtexas.wp_comments                          OKqqtexas.wp_links                             OKqqtexas.wp_options                           OKqqtexas.wp_postmeta                          OK

為了安全起見,以下兩種方法不建議在生產環境中使用
#mysqlcheck -a -o -r -p //檢查最佳化並修複所有的資料庫
#mysqlcheck -A -o -r 資料庫名稱 -p //修複指定的資料庫

 
參數含意:
-a = Analyse given tables. //分析資料表
-c = Check table for errors //檢查資料庫中錯誤(損壞)的表
-o = Optimise table //最佳化資料表
-r = Can fix almost anything except unique keys that aren’t unique // 修複損壞的資料表
-m = –medium-check



方法二:

使用命令myisamchk修複資料庫的MYI檔案

[[email protected] ~]# myisamchk -c -r /usr/local/mysql/data/qqtexas/zt_action.MYI- recovering (with sort) MyISAM-table ‘/usr/local/mysql/data/qqtexas/zt_action.MYI‘Data records: 21810- Fixing index 1- Fixing index 2

如果上述操作還不行,就使用 -f 強制執行修複;即

myisamchk -c -r -f /usr/local/mysql/data/qqtexas/zt_action.MYI


 
mysqlcheck說明:
mysqlcheck用戶端可以檢查和修複MyISAM表。它還可以最佳化和分析表。

mysqlcheck的功能類似myisamchk,但其工作不同。主要差別是當mysqld伺服器在運行時必須使用mysqlcheck,而myisamchk應用於服

務器沒有運行時。使用mysqlcheck的好處是不需要停止伺服器來檢查或修複表。使用myisamchk修複失敗是無法復原的。

Mysqlcheck為使用者提供了一種方便的使用SQL語句CHECK TABLE、REPAIR TABLE、ANALYZE TABLE和OPTIMIZE TABLE的方式。它確定

在要執行的操作中使用使用哪個語句,然後將語句發送到要執行的伺服器上。

參考:http://www.vpsee.com/ 

      http://www.cnblogs.com/zhoujinyi/archive/2013/05/10/3070667.html

      http://www.javatang.com/archives/category/database 

本文出自 “從心開始” 部落格,請務必保留此出處http://hao360.blog.51cto.com/5820068/1636856

解決MySQL Table '***' is marked as crashed and should be repaired問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.