[MySQL] 怎樣使用Mysqlcheck來檢查和修複, 最佳化表

來源:互聯網
上載者:User

標籤:文檔   pos   list   內容   情況下   nlog   5.6   blank   bsp   

mysqlcheck 是 MySQL 內建的一個工具,作用就是保養 表,其實就是檢查,分析,修複和最佳化了。下面來介紹 mysqlcheck 工具的簡單使用,官方文檔在這裡

原文網址:http://blog.csdn.net/orangleliu/article/details/63275154

以下的例子都是基於 MySQL 5.6 版本運行狀態下(mysqlcheck是個線上工具), 不同的儲存引擎對於這個命令的支援程度不同(指的是 check, repair, analyze, optimize),下面內容偏於操作,主要基於 innodb 引擎。

提示:OPTIMIZE 在大表時候可能會消耗很多時間,不清楚原理情況下請謹慎使用!!! innodb 一般不用 OPTIMIZE,請參見 Using MySQL OPTIMIZE tables? For InnoDB? Stop

檢查特定的表

注意在shell中執行,不是在mysql的互動環境下

如果應用中提示某個表壞了,使用下面的命令來檢查。

$ mysqlcheck -c newmandela order -uroot -pEnter password:newmandela.order OK

newmandela 是庫名, order是表名,還需要輸入使用者名稱和密碼

檢查一個庫中的所有表
$ mysqlcheck -c newmandela -uroot -pEnter password:newmandela.account                                 OKnewmandela.alarm                                   OKnewmandela.alarm_settings                          OKnewmandela.auth_group                              OKnewmandela.auth_group_permissions                  OKnewmandela.auth_permission                         OK...
檢查所有庫中的所有表

全部的庫和表都檢查一遍了。

$mysqlcheck -c --all-databases -uroot -pEnter password:apmonitor.acinfo                                   OKapmonitor.apdailysts                               OKapmonitor.apinfo                                   OKapmonitor.apmonthsts                               OKapmonitor.apscanlog                                OKapmonitor.auth_group                               OK...

如果只想檢查某幾個庫呢? 可以使用 –databases 參數

$ mysqlcheck -c --databases newmandela radius -uroot -pEnter password:newmandela.account                                 OKnewmandela.alarm                                   OKnewmandela.alarm_settings                          OKnewmandela.auth_group                              OK...
使用 mysqlcheck 分析表
$ mysqlcheck -a radius payment_transactionrecord  -uroot -pEnter password:radius.payment_transactionrecord                   Table is already up to date

上面的命令 用來分析 radius 庫的 payment_transactionrecord表, -a 表示 analyze

使用 mysqlcheck 最佳化表
# mysqlcheck -o radius payment_transactionrecord  -uroot -pEnter password:radius.payment_transactionrecord                   OK

-o 代表 optimize ,這裡是最佳化 radius 庫的 payment_transactionrecord 表

使用 mysqlcheck 修複表
# mysqlcheck -r radius payment_transactionrecord  -uroot -pEnter password:radius.payment_transactionrecord                   OK

-r 代表 repair ,這裡是 修複 radius 庫的 payment_transactionrecord 表

檢查,最佳化,修複表組合命令
# mysqlcheck -uroot -p --auto-repair -c -o newmandelaError:  mysqlcheck doesn‘t support multiple contradicting commands.

上面的命令報錯了,去掉 -c

# mysqlcheck -uroot -p --auto-repair -o newmandelaEnter password:newmandela.accountnote     : Table does not support optimize, doing recreate + analyze insteadstatus   : OKnewmandela.alarmnote     : Table does not support optimize, doing recreate + analyze insteadstatus : OKnewmandela.alarm_settingsnote : Table does not support optimize, doing recreate + analyze insteadstatus : OK

每張表都出現了 Table does not support optimize, doing recreate + analyze instead, 代表什麼意思呢? 它的意思不是說 innodb 引擎不支援 最佳化,可以參考 http://stackoverflow.com/questions/30635603/what-does-table-does-not-support-optimize-doing-recreate-analyze-instead-me 的回答。

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
著作權聲明:本文為orangleliu (http://blog.csdn.net/orangleliu/)原創文章,自由傳播,文章轉載請聲明, 多謝。

[MySQL] 怎樣使用Mysqlcheck來檢查和修複, 最佳化表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.