{"id":33459,"date":"2023-06-07T11:55:59","date_gmt":"2023-06-07T03:55:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=33459"},"modified":"2023-07-31T00:25:48","modified_gmt":"2023-07-30T16:25:48","slug":"mysql-update%e4%b8%bb%e9%94%ae%e6%9b%b4%e6%96%b0%e5%be%88%e6%85%a2%e4%bc%9a%e6%98%af%e4%bb%80%e4%b9%88%e5%8e%9f%e5%9b%a0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/33459.html","title":{"rendered":"mysql update\u4e3b\u952e\u66f4\u65b0\u5f88\u6162\u4f1a\u662f\u4ec0\u4e48\u539f\u56e0"},"content":{"rendered":"<blockquote class=\"wp-block-quote\">\n<p>\u56e0\u4e3aMySQL\u7684Optimizer\uff08\u4f18\u5316\u5143\u4ef6\uff09\u5728\u4f18\u5316SQL\u8bed\u53e5\u65f6\uff0c\u9996\u5148\u9700\u8981\u6536\u96c6\u4e00\u4e9b\u76f8\u5173\u4fe1\u606f\uff0c\u5176\u4e2d\u5c31\u5305\u62ec\u8868\u7684cardinality\uff08\u53ef\u4ee5\u7ffb\u8bd1\u4e3a\u201c\u6563\u5217\u7a0b\u5ea6\u201d\uff09\uff0c\u5b83\u8868\u793a\u67d0\u4e2a\u7d22\u5f15\u5bf9\u5e94\u7684\u5217\u5305\u542b\u591a\u5c11\u4e2a\u4e0d\u540c\u7684\u503c\u2014\u2014\u5982\u679ccardinality\u5927\u5927\u5c11\u4e8e\u6570\u636e\u7684\u5b9e\u9645\u6563\u5217\u7a0b\u5ea6\u3002<\/p>\n<\/blockquote>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" alt=\"\" class=\"wp-image-33460\" decoding=\"async\" height=\"421\" sizes=\"(max-width: 680px) 100vw, 680px\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/06\/\u6dfb\u52a0\u6807\u9898-18-3.png?x-oss-process=image\/auto-orient,1\/format,webp\" srcset=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/06\/\u6dfb\u52a0\u6807\u9898-18-3.png?x-oss-process=image\/auto-orient,1\/format,webp 680w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/06\/\u6dfb\u52a0\u6807\u9898-18-3-300x186.png 300w\" width=\"680\"\/><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001mysql update\u4e3b\u952e\u66f4\u65b0\u5f88\u6162\u7684\u539f\u56e0<\/strong><\/h2>\n<h3 class=\"wp-block-heading\"><strong>Analyze Table<\/strong><\/h3>\n<p>MySQL \u7684Optimizer\uff08\u4f18\u5316\u5143\u4ef6\uff09\u5728\u4f18\u5316SQL\u8bed\u53e5\u65f6\uff0c\u9996\u5148\u9700\u8981\u6536\u96c6\u4e00\u4e9b\u76f8\u5173\u4fe1\u606f\uff0c\u5176\u4e2d\u5c31\u5305\u62ec\u8868\u7684cardinality\uff08\u53ef\u4ee5\u7ffb\u8bd1\u4e3a\u201c\u6563\u5217\u7a0b\u5ea6\u201d\uff09\uff0c\u5b83\u8868\u793a\u67d0\u4e2a\u7d22\u5f15\u5bf9\u5e94\u7684\u5217\u5305\u542b\u591a\u5c11\u4e2a\u4e0d\u540c\u7684\u503c\u2014\u2014\u5982\u679ccardinality\u5927\u5927\u5c11\u4e8e\u6570\u636e\u7684\u5b9e\u9645\u6563\u5217\u7a0b\u5ea6\uff0c\u90a3\u4e48\u7d22\u5f15\u5c31\u57fa\u672c\u5931\u6548\u4e86\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528SHOW INDEX\u8bed\u53e5\u6765\u67e5\u770b\u7d22\u5f15\u7684\u6563\u5217\u7a0b\u5ea6\uff1a<\/p>\n<p>SHOW INDEX FROM PLAYERS;<\/p>\n<p>TABLE KEY_NAME COLUMN_NAME CARDINALITY<\/p>\n<p>PLAYERS PRIMARY PLAYERNO 14<\/p>\n<p>\u56e0\u4e3a\u6b64\u65f6PLAYER\u8868\u4e2d\u4e0d\u540c\u7684PLAYERNO\u6570\u91cf\u8fdc\u8fdc\u591a\u4e8e14\uff0c\u7d22\u5f15\u57fa\u672c\u5931\u6548\u3002<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u901a\u8fc7Analyze Table\u8bed\u53e5\u6765\u4fee\u590d\u7d22\u5f15\uff1a<\/p>\n<p>ANALYZE TABLE PLAYERS;<\/p>\n<p>SHOW INDEX FROM PLAYERS;<\/p>\n<p>\u7ed3\u679c\u662f\uff1a<\/p>\n<p>TABLE KEY_NAME COLUMN_NAME CARDINALITY<\/p>\n<p>PLAYERS PRIMARY PLAYERNO 1000<\/p>\n<p>\u6b64\u65f6\u7d22\u5f15\u5df2\u7ecf\u4fee\u590d\uff0c\u67e5\u8be2\u6548\u7387\u5927\u5927\u63d0\u9ad8\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u5f00\u542f\u4e86binlog\uff0c\u90a3\u4e48Analyze Table\u7684\u7ed3\u679c\u4e5f\u4f1a\u5199\u5165binlog\uff0c\u6211\u4eec\u53ef\u4ee5\u5728analyze\u548ctable\u4e4b\u95f4\u6dfb\u52a0\u5173\u952e\u5b57local\u53d6\u6d88\u5199\u5165\u3002<\/p>\n<h3 class=\"wp-block-heading\"><strong>Checksum Table<\/strong><\/h3>\n<p>\u6570\u636e\u5728\u4f20\u8f93\u65f6\uff0c\u53ef\u80fd\u4f1a\u53d1\u751f\u53d8\u5316\uff0c\u4e5f\u6709\u53ef\u80fd\u56e0\u4e3a\u5176\u5b83\u539f\u56e0\u635f\u574f\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u6570\u636e\u7684\u4e00\u81f4\uff0c\u6211\u4eec\u53ef\u4ee5\u8ba1\u7b97checksum\uff08\u6821\u9a8c\u503c\uff09\u3002<\/p>\n<p>\u4f7f\u7528MyISAM\u5f15\u64ce\u7684\u8868\u4f1a\u628achecksum\u5b58\u50a8\u8d77\u6765\uff0c\u79f0\u4e3alive checksum\uff0c\u5f53\u6570\u636e\u53d1\u751f\u53d8\u5316\u65f6\uff0cchecksum\u4f1a\u76f8\u5e94\u53d8\u5316\u3002<\/p>\n<p>\u5728\u6267\u884cChecksum Table\u65f6\uff0c\u53ef\u4ee5\u5728\u6700\u540e\u6307\u5b9a\u9009\u9879qiuck\u6216\u662fextended\uff1bquick\u8868\u793a\u8fd4\u56de\u5b58\u50a8\u7684checksum\u503c\uff0c\u800cextended\u4f1a\u91cd\u65b0\u8ba1\u7b97checksum\uff0c\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u9009\u9879\uff0c\u5219\u9ed8\u8ba4\u4f7f\u7528extended\u3002<\/p>\n<h3 class=\"wp-block-heading\"><strong>Optimize Table<\/strong><\/h3>\n<p>\u7ecf\u5e38\u66f4\u65b0\u6570\u636e\u7684\u78c1\u76d8\u9700\u8981\u6574\u7406\u788e\u7247\uff0c\u6570\u636e\u5e93\u4e5f\u662f\u8fd9\u6837\uff0cOptimize Table\u8bed\u53e5\u5bf9MyISAM\u548cInnoDB\u7c7b\u578b\u7684\u8868\u90fd\u6709\u6548\u3002<\/p>\n<p>\u5982\u679c\u8868\u7ecf\u5e38\u66f4\u65b0\uff0c\u5c31\u5e94\u5f53\u5b9a\u671f\u8fd0\u884cOptimize Table\u8bed\u53e5\uff0c\u4fdd\u8bc1\u6548\u7387\u3002<\/p>\n<p>\u4e0eAnalyze Table\u4e00\u6837\uff0cOptimize Table\u4e5f\u53ef\u4ee5\u4f7f\u7528local\u6765\u53d6\u6d88\u5199\u5165binlog\u3002<\/p>\n<h3 class=\"wp-block-heading\"><strong>Check Table<\/strong><\/h3>\n<p>\u6570\u636e\u5e93\u7ecf\u5e38\u53ef\u80fd\u9047\u5230\u9519\u8bef\uff0c\u8b6c\u5982\u6570\u636e\u5199\u5165\u78c1\u76d8\u65f6\u53d1\u751f\u9519\u8bef\uff0c\u6216\u662f\u7d22\u5f15\u6ca1\u6709\u540c\u6b65\u66f4\u65b0\uff0c\u6216\u662f\u6570\u636e\u5e93\u672a\u5173\u95edMySQL\u5c31\u505c\u6b62\u4e86\u3002<\/p>\n<p>\u9047\u5230\u8fd9\u4e9b\u60c5\u51b5\uff0c\u6570\u636e\u5c31\u53ef\u80fd\u53d1\u751f\u9519\u8bef\uff1a<\/p>\n<p>Incorrect key file for table: \u2019 \u2018. Try to repair it.<\/p>\n<p>\u6b64\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Check Table\u8bed\u53e5\u6765\u68c0\u67e5\u8868\u53ca\u5176\u5bf9\u5e94\u7684\u7d22\u5f15\u3002<\/p>\n<p>\u8b6c\u5982\u6211\u4eec\u8fd0\u884c<\/p>\n<p>CHECK TABLE PLAYERS;<\/p>\n<p>\u7ed3\u679c\u662f<\/p>\n<p>TABLE OP MSG_TYPE MSG_TEXT<\/p>\n<p>TENNIS.PLAYERS check status OK<\/p>\n<p>MySQL\u4f1a\u4fdd\u5b58\u8868\u6700\u8fd1\u4e00\u6b21\u68c0\u67e5\u7684\u65f6\u95f4\uff0c\u6bcf\u6b21\u8fd0\u884ccheck table\u90fd\u4f1a\u5b58\u50a8\u8fd9\u4e9b\u4fe1\u606f\uff1a<\/p>\n<p>\u6267\u884c<\/p>\n<p>SELECT TABLE_NAME, CHECK_TIME<\/p>\n<p>FROM INFORMATION_SCHEMA.TABLES<\/p>\n<p>WHERE TABLE_NAME = \u2018PLAYERS\u2019<\/p>\n<p>AND TABLE_SCHEMA = \u2018TENNIS\u2019; \/TENNIS\u662f\u6570\u636e\u5e93\u540d\/<\/p>\n<p>\u7ed3\u679c\u662f<\/p>\n<p>TABLE_NAME CHECK_TIME<\/p>\n<p>PLAYERS 2006-08-21 16:44:25<\/p>\n<p>Check Table\u8fd8\u53ef\u4ee5\u6307\u5b9a\u5176\u5b83\u9009\u9879\uff1a<\/p>\n<p>UPGRADE\uff1a\u7528\u6765\u6d4b\u8bd5\u5728\u66f4\u65e9\u7248\u672c\u7684MySQL\u4e2d\u5efa\u7acb\u7684\u8868\u662f\u5426\u4e0e\u5f53\u524d\u7248\u672c\u517c\u5bb9\u3002<\/p>\n<p>QUICK\uff1a\u901f\u5ea6\u975e\u5e38\u5feb\u7684\u9009\u9879\uff0c\u5728\u68c0\u67e5\u5404\u5217\u7684\u6570\u636e\u65f6\uff0c\u4e0d\u4f1a\u68c0\u67e5\u94fe\u63a5\uff08link\uff09\u7684\u6b63\u786e\u4e0e\u5426\uff0c\u5982\u679c\u6ca1\u6709\u9047\u5230\u4ec0\u4e48\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u9009\u9879\u3002<\/p>\n<p>FAST\uff1a\u53ea\u68c0\u67e5\u8868\u662f\u5426\u6b63\u5e38\u5173\u95ed\uff0c\u5982\u679c\u5728\u7cfb\u7edf\u6389\u7535\u4e4b\u540e\u6ca1\u6709\u9047\u5230\u4e25\u91cd\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u9009\u9879\u3002<\/p>\n<p>CHANGED\uff1a\u53ea\u68c0\u67e5\u4e0a\u6b21\u68c0\u67e5\u65f6\u95f4\u4e4b\u540e\u66f4\u65b0\u7684\u6570\u636e\u3002<\/p>\n<p>MEDIUM\uff1a\u9ed8\u8ba4\u7684\u9009\u9879\uff0c\u4f1a\u68c0\u67e5\u7d22\u5f15\u6587\u4ef6\u548c\u6570\u636e\u6587\u4ef6\u4e4b\u95f4\u7684\u94fe\u63a5\u6b63\u786e\u6027\u3002<\/p>\n<p>EXTENDED\uff1a\u6700\u6162\u7684\u9009\u9879\uff0c\u4f1a\u8fdb\u884c\u5168\u9762\u7684\u68c0\u67e5\u3002<\/p>\n<h3 class=\"wp-block-heading\"><strong>Repair Table<\/strong><\/h3>\n<p>\u7528\u4e8e\u4fee\u590d\u8868\uff0c\u53ea\u5bf9MyISAM\u548cARCHIVE\u7c7b\u578b\u7684\u8868\u6709\u6548\u3002<\/p>\n<p>\u8fd9\u6761\u8bed\u53e5\u540c\u6837\u53ef\u4ee5\u6307\u5b9a\u9009\u9879\uff1a<\/p>\n<p>QUICK\uff1a\u975e\u5e38\u5feb\u7684\u9009\u9879\uff0c\u53ea\u4fee\u590d\u7d22\u5f15\u6811\u3002<\/p>\n<p>EXTENDED\uff1a\u6700\u6162\u7684\u9009\u9879\uff0c\u9700\u8981\u9010\u884c\u91cd\u5efa\u7d22\u5f15\u3002<\/p>\n<p>USE_FRM\uff1a\u53ea\u6709\u5f53MYI\u6587\u4ef6\u4e22\u5931\u65f6\u624d\u4f7f\u7528\u8fd9\u4e2a\u9009\u9879\uff0c\u5168\u9762\u91cd\u5efa\u6574\u4e2a\u7d22\u5f15\u3002<\/p>\n<p>\u4e0eAnalyze Table\u4e00\u6837\uff0cRepair Table\u4e5f\u53ef\u4ee5\u4f7f\u7528local\u6765\u53d6\u6d88\u5199\u5165binlog\u3002<\/p>\n<p><strong>\u5ef6\u4f38\u9605\u8bfb\uff1a<\/strong><\/p>\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001Navicat\u662f\u4ec0\u4e48<\/strong><\/h2>\n<p>Navicat\u662f\u4e00\u5957\u5feb\u901f\u3001\u53ef\u9760\u548c\u5168\u9762\u7684\u6570\u636e\u5e93\u7ba1\u7406\u5de5\u5177\uff0c\u4e13\u95e8\u7528\u4e8e\u7b80\u5316\u6570\u636e\u5e93\u7ba1\u7406\u548c\u964d\u4f4e\u7ba1\u7406\u6210\u672c\u3002Navicat\u56fe\u5f62\u754c\u9762\u76f4\u89c2\uff0c\u63d0\u4f9b\u7b80\u4fbf\u7684\u7ba1\u7406\u65b9\u6cd5\uff0c\u8bbe\u8ba1\u548c\u64cd\u4f5cMySQL\u3001MariaDB\u3001SQL Server\u3001Oracle\u3001PostgreSQL\u548cSQLite\u7684\u6570\u636e\u3002<\/p>\n<p>Navicat\u63d0\u4f9b\u4e00\u4e2a\u76f4\u89c2\u548c\u8bbe\u8ba1\u5b8c\u5584\u7684\u7528\u6237\u754c\u9762\uff0c\u7528\u4e8e\u521b\u5efa\u3001\u4fee\u6539\u548c\u7ba1\u7406\u8d44\u6599\u5e93\u7684\u6240\u6709\u5bf9\u8c61\uff0c\u4f8b\u5982\u8868\u3001\u89c6\u56fe\u3001\u51fd\u6570\u6216\u8fc7\u7a0b\u3001\u7d22\u5f15\u3001\u89e6\u53d1\u5668\u548c\u5e8f\u5217\u3002\u6211\u4eec\u7684\u8868\u8bbe\u8ba1\u5668\u5e2e\u52a9\u7528\u6237\u521b\u5efa\u548c\u4fee\u6539\u6570\u636e\u5e93\u7684\u8868\uff0c\u8ba9\u8bbe\u7f6e\u9ad8\u7ea7\u9009\u9879\uff0c\u5982\u5173\u7cfb\u3001\u9650\u5236\u3001\u89e6\u53d1\u5668\u548c\u66f4\u591a\u3002<\/p>\n<p>\u4f7f\u7528Navicat\u6d4f\u89c8\u548c\u4fee\u6539\u6570\u636e\uff0c\u63d2\u5165\u3001\u7f16\u8f91\u3001\u5220\u9664\u6570\u636e\u6216\u590d\u5236\u548c\u7c98\u8d34\u8bb0\u5f55\u5230\u6570\u636e\u8868\u5f62\u5f0f\u7684\u6570\u636e\u7f16\u8f91\u5668\uff0cNavicat\u5c06\u8fd0\u884c\u76f8\u5e94\u7684\u547d\u4ee4\uff08\u4f8b\u5982INSERT\u6216UPDATE\uff09\uff0c\u514d\u9664\u5199\u590d\u6742\u7684SQL\u3002\u5e7f\u6cdb\u7684\u6570\u636e\u7f16\u8f91\u5de5\u5177\u4ee4\u7f16\u8f91\u5de5\u4f5c\u66f4\u4e3a\u65b9\u4fbf\uff0c\u4f8b\u5982\u5916\u952e\u67e5\u627e\u3001set\/enum\u9009\u62e9\u5668\u548c\u8bb0\u5f55\u7b5b\u9009\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u56e0\u4e3aMySQL\u7684Optimizer\uff08\u4f18\u5316\u5143\u4ef6\uff09\u5728\u4f18\u5316SQL\u8bed\u53e5\u65f6\uff0c\u9996\u5148\u9700\u8981\u6536\u96c6\u4e00\u4e9b\u76f8\u5173\u4fe1\u606f\uff0c\u5176\u4e2d\u5c31\u5305\u62ec\u8868\u7684ca [&hellip;]","protected":false},"author":1,"featured_media":33460,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/33459"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=33459"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/33459\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/33460"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=33459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=33459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=33459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}