工作中會遇到網站訪問提示MySQL錯誤:Table XXX is marked as crashed and should be repaired。除了可以通過安裝phpmyadmin進行修復,還可以通過mysqlcheak命令進行修復。
1、修復某個數據庫所有表
mysqlcheck -r -uroot -p dbname
2、修復指定表
mysqlcheck -r -uroot -p dbname tablename
3、修復所有數據庫表
mysqlcheck -A -o -r -p -uroot -p
4、自動檢查、優化修復、分析所有表
mysqlcheck -Aao --auto-repair -uroot -p
5、myisamchk 修復表
myisamchk -r 數據文件目錄/數據表名.MYI
myisamchk -r /www/wdlinux/mysql/var/*/*.MYI
#如數據庫表比較大修復失敗,可加--sort_buffer_size=2G
myisamchk -r /www/wdlinux/mysql/var/*/*.MYI --sort_buffer_size=2G
6、mysqlcheck 常用選項
-A, –all-databases 表示所有庫
-a, –analyze 分析表
-o, –optimize 優化表
-r, –repair 修復表錯誤
-c, –check 檢查表是否出錯
–auto-repair 自動修復損壞的表
-B, –databases 選擇多個庫
-1, –all-in-1 Use one query per database with tables listed in a comma separated way
-C, –check-only-changed 檢查表最后一次檢查之后的變動
-g, –check-upgrade Check for version dependent changes in the tables
-F, –fast Check tables that are not closed properly
–fix-db-names Fix DB names
–fix-table-names Fix table names
-f, –force Continue even when there is an error
-e, –extended Perform extended check on a table. This will take a long time to execute.
-m, –medium-check Faster than extended check option, but does most checks
-q, –quick Faster than medium check option