{"id":162,"date":"2016-08-17T09:29:03","date_gmt":"2016-08-17T01:29:03","guid":{"rendered":"http:\/\/www.cxybj.com\/?p=162"},"modified":"2016-08-17T09:29:03","modified_gmt":"2016-08-17T01:29:03","slug":"mysql%e4%bf%ae%e5%a4%8d%e6%8d%9f%e5%9d%8f%e8%a1%a8%e5%91%bd%e4%bb%a4mysqlcheck%e5%92%8c%e8%87%aa%e5%8a%a8%e4%bf%ae%e5%a4%8d%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/www.cxybj.com\/?p=162","title":{"rendered":"Mysql\u4fee\u590d\u635f\u574f\u8868\u547d\u4ee4mysqlcheck\u548c\u81ea\u52a8\u4fee\u590d\u811a\u672c"},"content":{"rendered":"<p>mysql \u8868\u635f\u574f\u4fee\u590d\u8868\u7684\u5404\u79cd\u65b9\u6cd5<\/p>\n<p>1\u3001mysqlcheck \u8fdb\u884c\u8868\u4fee\u590d<\/p>\n<p>\u4f7f\u7528mysqlcheck \u547d\u4ee4\u5bf9\u8868\u8fdb\u884c\u4fee\u590d<\/p>\n<p>#mysqlcheck -uuser -ppassword database\u00a0 table\u00a0 -c\u00a0 #\u68c0\u67e5\u5355\u4e2a\u8868\u662f\u5426\u635f\u574f<\/p>\n<p>#mysqlcheck -uuser -ppassword database\u00a0 -c\u00a0 #\u68c0\u67e5\u6574\u4e2a\u5e93\u90a3\u4e9b\u8868\u635f\u574f<\/p>\n<p>\u9996\u5148\u68c0\u67e5\u6570\u636e\u5e93\u7684\u90a3\u4e9b\u8868\u635f\u574f\uff0c\u5982\u679c\u80fd\u5b9a\u4f4d\u5230\u90a3\u5f20\u8868\u635f\u574f\u53ef\u4ee5\u76f4\u63a5\u5bf9\u8868\u4fee\u590d<\/p>\n<p>#mysqlcheck -uuser -ppassword database\u00a0 table\u00a0 -r # \u4fee\u590d\u6570\u636e\u8868<\/p>\n<p>#mysqlcheck -uuser -ppassword database\u00a0\u00a0 -r # \u4fee\u590d\u6574\u4e2a\u6570\u636e\u5e93<\/p>\n<p>\u66f4\u591a\u53c2\u6570 \u67e5\u770b mysqlcheck \u2013help<\/p>\n<p>2\u3001myisamchk \u4fee\u590dmysql\u8868<\/p>\n<p>Myisamchk\u662fMyISAM\u8868\u7ef4\u62a4\u7684\u4e00\u4e2a\u975e\u5e38\u5b9e\u7528\u7684\u5de5\u5177\u3002\u53ef\u4ee5\u4f7f\u7528myisamchk\u5b9e\u7528\u7a0b\u5e8f\u6765\u83b7\u5f97\u6709\u5173\u6570\u636e\u5e93\u8868\u7684\u4fe1\u606f\u6216\u68c0\u67e5\u3001\u4fee\u590d\u3001\u4f18\u5316\u4ed6\u4eec\u3002myisamchk\u9002\u7528MyISAM\u8868(\u5bf9\u5e94.MYI\u548c.MYD\u6587\u4ef6\u7684\u8868)\u3002<\/p>\n<p>Myisamchk \u9009\u9879\u89e3\u91ca<\/p>\n<p>\u2013debug=debug_options, -# debug_options<br \/>\n\u8f93\u51fa\u8c03\u8bd5\u8bb0\u5f55\u6587\u4ef6\u3002debug_options\u5b57\u7b26\u4e32\u7ecf\u5e38\u662f\u2019d:t:o,filename\u2019\u3002<\/p>\n<p>\u2013silent\uff0c-s<br \/>\n\u6c89\u9ed8\u6a21\u5f0f\u3002\u4ec5\u5f53\u53d1\u751f\u9519\u8bef\u65f6\u5199\u8f93\u51fa\u3002<\/p>\n<p>\u2013wait, -w<br \/>\n\u5982\u679c\u8868\u88ab\u9501\u5b9a\uff0c\u4e0d\u662f\u63d0\u793a\u9519\u8bef\u7ec8\u6b62\uff0c\u800c\u662f\u5728\u7ee7\u7eed\u524d\u7b49\u5f85\u5230\u8868\u88ab\u89e3\u9501\u3002<br \/>\n\u5982\u679c\u4e0d\u4f7f\u7528\u2013skip-external-locking\uff0c\u53ef\u4ee5\u968f\u65f6\u4f7f\u7528myisamchk\u6765\u68c0\u67e5\u8868\u3002\u5f53\u68c0\u67e5\u8868\u65f6\uff0c\u6240\u6709\u5c1d\u8bd5\u66f4\u65b0\u8868\u7684\u5ba2\u6237\u7aef\u5c06\u7b49\u5f85\uff0c\u76f4\u5230myisamchk\u51c6\u5907\u597d\u53ef\u4ee5\u7ee7\u7eed\u3002<br \/>\n\u8bf7\u6ce8\u610f\u5982\u679c\u7528\u2013skip-external-locking\u9009\u9879\u8fd0\u884cmysqld\uff0c\u53ea\u80fd\u7528\u53e6\u4e00\u4e2amyisamchk\u547d\u4ee4\u9501\u5b9a\u8868\u3002<\/p>\n<p>\u2013var_name=value<br \/>\n\u53ef\u4ee5\u901a\u8fc7\u2013var_name=value\u9009\u9879\u8bbe\u7f6e\u4e0b\u9762\u7684\u53d8\u91cf:<\/p>\n<p>\u2013check, -c<br \/>\n\u68c0\u67e5\u8868\u7684\u9519\u8bef\u3002\u5982\u679c\u4f60\u4e0d\u660e\u786e\u6307\u5b9a\u64cd\u4f5c\u7c7b\u578b\u9009\u9879\uff0c\u8fd9\u5c31\u662f\u9ed8\u8ba4\u64cd\u4f5c\u3002<\/p>\n<p>\u2013check-only-changed, -C<br \/>\n\u53ea\u68c0\u67e5\u4e0a\u6b21\u68c0\u67e5\u540e\u6709\u53d8\u66f4\u7684\u8868\u3002<\/p>\n<p>\u2013extend-check, -e<br \/>\n\u975e\u5e38\u4ed4\u7ec6\u5730\u68c0\u67e5\u8868\u3002\u5982\u679c\u8868\u6709\u8bb8\u591a\u7d22\u5f15\u5c06\u4f1a\u76f8\u5f53\u6162\u3002<\/p>\n<p>\u2013fast\uff0c-F<br \/>\n\u53ea\u68c0\u67e5\u6ca1\u6709\u6b63\u786e\u5173\u95ed\u7684\u8868\u3002<\/p>\n<p>\u2013force, -f<br \/>\n\u5982\u679cmyisamchk\u53d1\u73b0\u8868\u5185\u6709\u4efb\u4f55\u9519\u8bef\uff0c\u5219\u81ea\u52a8\u8fdb\u884c\u4fee\u590d\u3002<\/p>\n<p>\u2013information, -i<br \/>\n\u6253\u5370\u6240\u68c0\u67e5\u8868\u7684\u7edf\u8ba1\u4fe1\u606f\u3002<\/p>\n<p>\u2013medium-check, -m<br \/>\n\u6bd4\u2013extend-check\u66f4\u5feb\u901f\u5730\u8fdb\u884c\u68c0\u67e5\u3002\u53ea\u80fd\u53d1\u73b099.99%\u7684\u9519\u8bef<\/p>\n<p>\u2013update-state, -U<br \/>\n\u5c06\u4fe1\u606f\u4fdd\u5b58\u5728.MYI\u6587\u4ef6\u4e2d\uff0c\u6765\u8868\u793a\u8868\u68c0\u67e5\u7684\u65f6\u95f4\u4ee5\u53ca\u662f\u5426\u8868\u5d29\u6e83\u4e86\u3002\u8be5\u9009\u9879\u7528\u6765\u5145\u5206\u5229\u7528\u2013check-only-changed\u9009\u9879\uff0c<br \/>\n\u4f46\u5982\u679cmysqld\u670d\u52a1\u5668\u6b63\u4f7f\u7528\u8868\u5e76\u4e14\u6b63\u7528\u2013skip-external-locking\u9009\u9879\u8fd0\u884c\u65f6\u4e0d\u5e94\u4f7f\u7528\u8be5\u9009\u9879\u3002<\/p>\n<p>\u2013read-only, -T<br \/>\n\u4e0d\u8981\u5c06\u8868\u6807\u8bb0\u4e3a\u5df2\u7ecf\u68c0\u67e5\u3002\u5982\u679c\u4f60\u4f7f\u7528myisamchk\u6765\u68c0\u67e5\u6b63\u88ab\u5176\u5b83\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u800c\u6ca1\u6709\u9501\u5b9a\u7684\u8868\u5f88\u6709\u7528<\/p>\n<p>\u2013backup, -B<br \/>\n\u5c06.MYD\u6587\u4ef6\u5907\u4efd\u4e3afile_name-time.BAK<\/p>\n<p>\u2013character-sets-dir=path<br \/>\n\u5b57\u7b26\u96c6\u5b89\u88c5\u76ee\u5f55\u3002<\/p>\n<p>\u2013correct-checksum<br \/>\n\u7ea0\u6b63\u8868\u7684\u6821\u9a8c\u548c\u4fe1\u606f\u3002<\/p>\n<p>\u2013data-file-length=len, -D len<br \/>\n\u6570\u636e\u6587\u4ef6\u7684\u6700\u5927\u957f\u5ea6<\/p>\n<p>\u2013extend-check\uff0c-e<br \/>\n\u8fdb\u884c\u4fee\u590d\uff0c\u8bd5\u56fe\u4ece\u6570\u636e\u6587\u4ef6\u6062\u590d\u6bcf\u4e00\u884c\u3002\u4e00\u822c\u60c5\u51b5\u4f1a\u53d1\u73b0\u5927\u91cf\u7684\u5783\u573e\u884c\u3002\u4e0d\u8981\u4f7f\u7528\u8be5\u9009\u9879,\u9664\u975e\u4f60\u4e0d\u987e\u540e\u679c\u3002<\/p>\n<p>\u2013force, -f<br \/>\n\u8986\u76d6\u65e7\u7684\u4e2d\u95f4\u6587\u4ef6(\u6587\u4ef6\u540d\u7c7b\u4f3ctbl_name.TMD)\uff0c\u800c\u4e0d\u662f\u4e2d\u65ad<\/p>\n<p>\u2013keys-used=val, -k val<br \/>\n\u5bf9\u4e8emyisamchk\uff0c\u8be5\u9009\u9879\u503c\u4e3a\u4f4d\u503c\uff0c\u8bf4\u660e\u8981\u66f4\u65b0\u7684\u7d22\u5f15\u3002\u9009\u9879\u503c\u7684\u6bcf\u4e00\u4e2a\u4e8c\u8fdb\u5236\u4f4d\u5bf9\u5e94\u8868\u7684\u4e00\u4e2a\u7d22\u5f15\uff0c\u5176\u4e2d\u7b2c\u4e00\u4e2a\u7d22\u5f15\u5bf9\u5e94\u4f4d0\u3002<br \/>\n\u9009\u9879\u503c0\u7981\u7528\u5bf9\u6240\u6709\u7d22\u5f15\u7684\u66f4\u65b0\uff0c\u53ef\u4ee5\u4fdd\u8bc1\u5feb\u901f\u63d2\u5165\u3002\u901a\u8fc7myisamchk -r\u53ef\u4ee5\u91cd\u65b0\u6fc0\u6d3b\u88ab\u7981\u7528\u7684\u7d22\u5f15\u3002<\/p>\n<p>\u2013parallel-recover, -p<br \/>\n\u4e0e-r\u548c-n\u7684\u7528\u6cd5\u76f8\u540c\uff0c\u4f46\u4f7f\u7528\u4e0d\u540c\u7684\u7ebf\u7a0b\u5e76\u884c\u521b\u5efa\u6240\u6709\u952e\u3002<\/p>\n<p>\u2013quick\uff0c-q<br \/>\n\u4e0d\u4fee\u6539\u6570\u636e\u6587\u4ef6\uff0c\u5feb\u901f\u8fdb\u884c\u4fee\u590d\u3002<\/p>\n<p>\u2013recover, -r<br \/>\n\u53ef\u4ee5\u4fee\u590d\u51e0\u4e4e\u6240\u6709\u4e00\u5207\u95ee\u9898\uff0c\u9664\u975e\u552f\u4e00\u7684\u952e\u4e0d\u552f\u4e00\u65f6(\u5bf9\u4e8eMyISAM\u8868\uff0c\u8fd9\u662f\u975e\u5e38\u4e0d\u53ef\u80fd\u7684\u60c5\u51b5)\u3002\u5982\u679c\u4f60\u60f3\u8981\u6062\u590d\u8868\uff0c<br \/>\n\u8fd9\u662f\u9996\u5148\u8981\u5c1d\u8bd5\u7684\u9009\u9879\u3002\u5982\u679cmyisamchk\u62a5\u544a\u8868\u4e0d\u80fd\u7528-r\u6062\u590d\uff0c\u5219\u53ea\u80fd\u5c1d\u8bd5-o\u3002<br \/>\n\u5728\u4e0d\u592a\u53ef\u80fd\u7684\u60c5\u51b5\u4e0b-r\u5931\u8d25\uff0c\u6570\u636e\u6587\u4ef6\u4fdd\u6301\u5b8c\u597d\uff09\u3002<\/p>\n<p>\u2013safe-recover, -o<br \/>\n\u4f7f\u7528\u4e00\u4e2a\u8001\u7684\u6062\u590d\u65b9\u6cd5\u8bfb\u53d6\uff0c\u6309\u987a\u5e8f\u8bfb\u53d6\u6240\u6709\u884c\uff0c\u5e76\u6839\u636e\u627e\u5230\u7684\u884c\u66f4\u65b0\u6240\u6709\u7d22\u5f15\u6811\u3002\u8fd9\u6bd4-r\u6162\u4e9b\uff0c<br \/>\n\u4f46\u662f\u80fd\u5904\u7406-r\u4e0d\u80fd\u5904\u7406\u7684\u60c5\u51b5\u3002\u8be5\u6062\u590d\u65b9\u6cd5\u4f7f\u7528\u7684\u786c\u76d8\u7a7a\u95f4\u6bd4-r\u5c11\u3002\u4e00\u822c\u60c5\u51b5\uff0c\u4f60\u5e94\u9996\u5148\u7528-r\u7ef4\u4fee\uff0c\u5982\u679c-r\u5931\u8d25\u5219\u7528-o\u3002<\/p>\n<p>\u2013sort-recover, -n<br \/>\n\u5f3a\u5236myisamchk\u901a\u8fc7\u6392\u5e8f\u6765\u89e3\u6790\u952e\u503c\uff0c\u5373\u4f7f\u4e34\u65f6\u6587\u4ef6\u5c06\u53ef\u80fd\u5f88\u5927\u3002<\/p>\n<p>\u2013analyze\uff0c-a<br \/>\n\u5206\u6790\u952e\u503c\u7684\u5206\u5e03\u3002\u8fd9\u901a\u8fc7\u8ba9\u8054\u7ed3\u4f18\u5316\u5668\u66f4\u597d\u5730\u9009\u62e9\u8868\u5e94\u8be5\u4ee5\u4ec0\u4e48\u6b21\u5e8f\u8054\u7ed3\u548c\u5e94\u8be5\u4f7f\u7528\u54ea\u4e2a\u952e\u6765\u6539\u8fdb\u8054\u7ed3\u6027\u80fd\u3002<br \/>\n\u8981\u60f3\u83b7\u53d6\u5206\u5e03\u76f8\u5173\u4fe1\u606f\uff0c\u4f7f\u7528myisamchk \u2013description \u2013verbose tbl_name\u547d\u4ee4\u6216SHOW KEYS FROM tbl_name\u8bed\u53e5\u3002<\/p>\n<p>\u2013sort-index, -S<br \/>\n\u4ee5\u4ece\u9ad8\u5230\u4f4e\u7684\u987a\u5e8f\u6392\u5e8f\u7d22\u5f15\u6811\u5757\u3002\u8fd9\u5c06\u4f18\u5316\u641c\u5bfb\u5e76\u4e14\u5c06\u4f7f\u6309\u952e\u503c\u7684\u8868\u626b\u63cf\u66f4\u5feb\u3002<\/p>\n<p>\u2013set-auto-increment[=value], -A[value]<br \/>\n\u5f3a\u5236\u4ece\u7ed9\u5b9a\u503c\u5f00\u59cb\u7684\u65b0\u8bb0\u5f55\u4f7f\u7528AUTO_INCREMENT\u7f16\u53f7(\u6216\u5982\u679c\u5df2\u7ecf\u6709AUTO_INCREMENT\u503c\u5927\u5c0f\u7684\u8bb0\u5f55\uff0c\u5e94\u4f7f\u7528\u66f4\u9ad8\u503c)\u3002<br \/>\n\u5982\u679c\u672a\u6307\u5b9avalue\uff0c\u65b0\u8bb0\u5f55\u7684AUTO_INCREMENT\u7f16\u53f7\u5e94\u4f7f\u7528\u5f53\u524d\u8868\u7684\u6700\u5927\u503c\u52a0\u4e0a1\u3002<\/p>\n<p>\u2013description, -d<br \/>\n\u6253\u5370\u51fa\u5173\u4e8e\u8868\u7684\u63cf\u8ff0\u6027\u4fe1\u606f\u3002<\/p>\n<p>\u68c0\u67e5\u8868<\/p>\n<p>[root@nagios test]# myisamchk -e \u8868\u540d.MYI<br \/>\nChecking MyISAM file: \u8868\u540d.MYI<br \/>\nmyisanchk\u4fee\u590d\u8868<\/p>\n<p>[root@nagios test]# myisamchk -r \u8868\u540d.MYI<\/p>\n<p>3\u3001\u81ea\u52a8\u4fee\u590dmysql \u8868\u811a\u672c<\/p>\n<p>#!\/bin\/bash<br \/>\nmysql_host=localhost<br \/>\nmysql_user=root<br \/>\nmysql_pass=\u5bc6\u7801<br \/>\ndatabase=\u8981\u4fee\u590d\u7684\u6570\u636e\u5e93\u540d\u79f0<\/p>\n<p>tables=$(mysql -h$mysql_host -u$mysql_user -p$mysql_pass $database -A -Bse \u201cshow tables\u201d)<br \/>\nfor arg in $tables<br \/>\ndo<br \/>\ncheck_status=$(mysql -h$mysql_host -u$mysql_user -p$mysql_pass $database -A -Bse \u201ccheck table $arg\u201d | awk \u2018{ print $4 }\u2019)<br \/>\nif [ &#8220;$check_status&#8221; = &#8220;OK&#8221; ]<br \/>\nthen<br \/>\necho \u201c$arg is ok\u201d<br \/>\nelse<br \/>\necho $(mysql -h$mysql_host -u$mysql_user -p$mysql_pass $database -A -Bse \u201crepair table $arg\u201d)<\/p>\n<p>fi<br \/>\necho $(mysql -h$mysql_host -u$mysql_user -p$mysql_pass $database -A -Bse \u201coptimize table $arg\u201d)<br \/>\ndone<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysql \u8868\u635f\u574f\u4fee\u590d\u8868\u7684\u5404\u79cd\u65b9\u6cd5 1\u3001mysqlcheck &hellip; <a href=\"https:\/\/www.cxybj.com\/?p=162\" class=\"more-link\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,4,5],"tags":[],"_links":{"self":[{"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/posts\/162"}],"collection":[{"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=162"}],"version-history":[{"count":1,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/posts\/162\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=\/wp\/v2\/posts\/162\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/www.cxybj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cxybj.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}