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 -p
Enter password:
newmandela.order OK

newmandela 是库名, order是表名,还需要输入用户名和密码

检查一个库中的所有表

$ mysqlcheck -c newmandela -uroot -p
Enter password:
newmandela.account OK
newmandela.alarm OK
newmandela.alarm_settings OK
newmandela.auth_group OK
newmandela.auth_group_permissions OK
newmandela.auth_permission OK
...

检查所有库中的所有表

全部的库和表都检查一遍了。

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

如果只想检查某几个库呢? 可以使用 –databases 参数

$ mysqlcheck -c --databases newmandela radius -uroot -p
Enter password:
newmandela.account OK
newmandela.alarm OK
newmandela.alarm_settings OK
newmandela.auth_group OK
...

使用 mysqlcheck 分析表

$ mysqlcheck -a radius payment_transactionrecord  -uroot -p
Enter password:
radius.payment_transactionrecord Table is already up to date

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

使用 mysqlcheck 优化表

# mysqlcheck -o radius payment_transactionrecord  -uroot -p
Enter password:
radius.payment_transactionrecord OK

-o 代表 optimize ,这里是优化 radius 库的 payment_transactionrecord 表

使用 mysqlcheck 修复表

# mysqlcheck -r radius payment_transactionrecord  -uroot -p
Enter password:
radius.payment_transactionrecord OK

-r 代表 repair ,这里是 修复 radius 库的 payment_transactionrecord 表

检查,优化,修复表组合命令

# mysqlcheck -uroot -p --auto-repair -c -o newmandela
Error: mysqlcheck doesn't support multiple contradicting commands.

上面的命令报错了,去掉 -c

# mysqlcheck -uroot -p --auto-repair -o newmandela
Enter password:
newmandela.account
note : Table does not support optimize, doing recreate + analyze instead
status : OK
newmandela.alarm
note : Table does not support optimize, doing recreate + analyze instead
status : OK
newmandela.alarm_settings
note : Table does not support optimize, doing recreate + analyze instead
status : 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/)原创文章,自由传播,文章转载请声明, 多谢。

最新文章

  1. Android View的绘制流程
  2. Destoon B2B 调优SQL后 生成首页仍然慢或不成功的原因
  3. Apache Shiro 简单概念
  4. Xcode 8 在XIB中布局View尺寸1000*1000
  5. 又发现一个msdn的坑
  6. js模块方案
  7. POJ2823Sliding Window
  8. sql2005镜像实现
  9. C++之函数fgetc和fputc、fgets和fputs、fread和fwrite、fscanf和fprintf用法小结
  10. Delphi代码中嵌入ASM代码
  11. 使用Mockito进行单元测试【2】—— stub 和 高级特性[转]
  12. 数据库訪问技术之JDBC
  13. HTML5 Canvas爱心时钟代码
  14. Java实现打印日历的功能
  15. 20. Valid Parentheses (JAVA)
  16. vbs脚本,电脑说出指定内容
  17. Git 合并多次 commit 、 删除某次 commit
  18. NFS Server宕机后,NFS Client主机上df命令挂死
  19. Vue中使用watch来监听数据变化
  20. [How to] ROOT, Backup & Flash (MTKDroidTools, Spflashtool, CWM)

热门文章

  1. DZY Loves Math
  2. Linux二进制程序安装使用
  3. nginx配置-location
  4. 建站手册-浏览器信息:Mozilla 项目
  5. 显示等待WebDriverWait+lambda
  6. C# DotNetZip压缩单、多文件以及文件夹
  7. B. pSort
  8. 在WSL Ubuntu 下编译UPX详细步骤
  9. AOM
  10. vue (UI)