{"id":5129,"date":"2024-11-14T08:48:14","date_gmt":"2024-11-14T00:48:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5129\/"},"modified":"2024-11-14T08:48:14","modified_gmt":"2024-11-14T00:48:14","slug":"mysql%e6%80%8e%e4%b9%88%e7%94%a8%e7%b4%a2%e5%bc%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5129\/","title":{"rendered":"mysql\u600e\u4e48\u7528\u7d22\u5f15"},"content":{"rendered":"<p><strong>\u5982\u4f55\u4f7f\u7528  \u7d22\u5f15<\/strong><\/p>\n<p>\u7d22\u5f15\u662f MySQL \u6570\u636e\u5e93\u4e2d\u4e00\u79cd\u5f88\u91cd\u8981\u7684\u7ed3\u6784\uff0c\u5b83\u901a\u8fc7\u52a0\u5feb\u901f\u5ea6\u6765\u63d0\u5347\u67e5\u8be2\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 MySQL \u7d22\u5f15\u7684\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u7d22\u5f15<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 CREATE INDEX \u8bed\u53e5\u521b\u5efa\u7d22\u5f15\uff1a<\/p>\n<pre>CREATE INDEX name_index ON table_name(column_name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>name_index \u662f\u7d22\u5f15\u7684\u540d\u79f0\u3002<\/li>\n<li>table_name \u662f\u8981\u4e3a\u5176\u521b\u5efa\u7d22\u5f15\u7684\u8868\u3002<\/li>\n<li>column_name \u662f\u8981\u521b\u5efa\u7d22\u5f15\u7684\u5217\u3002<\/li>\n<\/ul>\n<p><strong>2. \u7d22\u5f15\u7c7b\u578b<\/strong><\/p>\n<p>MySQL \u652f\u6301\u591a\u79cd\u7d22\u5f15\u7c7b\u578b\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li> <strong>\u666e\u901a\u7d22\u5f15\uff1a<\/strong>\u6700\u5e38\u89c1\u7684\u7d22\u5f15\u7c7b\u578b\uff0c\u52a0\u5feb\u5bf9\u5217\u7684\u67e5\u627e\u3002<\/li>\n<li> <strong>\u552f\u4e00\u7d22\u5f15\uff1a<\/strong>\u4e0e\u666e\u901a\u7d22\u5f15\u7c7b\u4f3c\uff0c\u4f46\u786e\u4fdd\u5217\u4e2d\u7684\u503c\u552f\u4e00\u3002<\/li>\n<li> <strong>\u5168\u6587\u7d22\u5f15\uff1a<\/strong>\u7528\u4e8e\u5728\u6587\u672c\u5217\u4e2d\u8fdb\u884c\u5168\u6587\u641c\u7d22\u3002<\/li>\n<li> <strong>\u7a7a\u95f4\u7d22\u5f15\uff1a<\/strong>\u7528\u4e8e\u5728\u7a7a\u95f4\u6570\u636e\uff08\u5982\uff09\u4e2d\u8fdb\u884c\u67e5\u8be2\u3002<\/li>\n<\/ul>\n<p><strong>3. \u4f18\u5316\u7d22\u5f15\u4f7f\u7528<\/strong><\/p>\n<p>\u4e3a\u4e86\u4f18\u5316\u7d22\u5f15\u4f7f\u7528\uff0c\u53ef\u4ee5\u9075\u5faa\u4ee5\u4e0b\u51c6\u5219\uff1a<\/p>\n<ul>\n<li>\u53ea\u4e3a\u7ecf\u5e38\u67e5\u8be2\u7684\u5217\u521b\u5efa\u7d22\u5f15\u3002<\/li>\n<li>\u9009\u62e9\u67e5\u8be2\u4e2d\u9891\u7e41\u4f7f\u7528\u7684\u5217\u4f5c\u4e3a\u7d22\u5f15\u5217\u3002<\/li>\n<li>\u907f\u514d\u5728\u4e0d\u65ad\u66f4\u65b0\u7684\u5217\u4e0a\u521b\u5efa\u7d22\u5f15\u3002<\/li>\n<li>\u5b9a\u671f\u4f7f\u7528 ANALYZE \u547d\u4ee4\u66f4\u65b0\u7d22\u5f15\u7edf\u8ba1\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p><strong>4. \u5220\u9664\u7d22\u5f15<\/strong><\/p>\n<p>\u5982\u679c\u4e0d\u518d\u9700\u8981\u7d22\u5f15\uff0c\u53ef\u4ee5\u4f7f\u7528 DROP INDEX \u8bed\u53e5\u5c06\u5176\u5220\u9664\uff1a<\/p>\n<pre>DROP INDEX name_index ON table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u7d22\u5f15\u7684\u9650\u5236<\/strong><\/p>\n<p>\u867d\u7136\u7d22\u5f15\u5bf9\u6027\u80fd\u81f3\u5173\u91cd\u8981\uff0c\u4f46\u4e5f\u6709\u4ee5\u4e0b\u9650\u5236\uff1a<\/p>\n<ul>\n<li>\u521b\u5efa\u7d22\u5f15\u9700\u8981\u65f6\u95f4\u548c\u7a7a\u95f4\u5f00\u9500\u3002<\/li>\n<li>\u7d22\u5f15\u9700\u8981\u7ef4\u62a4\uff0c\u8fd9\u53ef\u80fd\u4f1a\u964d\u4f4e\u63d2\u5165\u548c\u66f4\u65b0\u64cd\u4f5c\u7684\u6027\u80fd\u3002<\/li>\n<li>MySQL \u4e2d\u7684\u7d22\u5f15\u6700\u591a\u652f\u6301 16 \u4e2a\u5217\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u7528\u7d22\u5f15\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 \u7d22\u5f15 \u7d22\u5f15\u662f MySQL \u6570\u636e\u5e93\u4e2d\u4e00\u79cd\u5f88\u91cd\u8981\u7684\u7ed3\u6784\uff0c\u5b83\u901a\u8fc7\u52a0\u5feb\u901f\u5ea6\u6765\u63d0\u5347\u67e5\u8be2\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 MySQL \u7d22\u5f15\u7684\u65b9\u6cd5\uff1a 1. \u521b\u5efa\u7d22\u5f15 \u53ef\u4ee5\u4f7f\u7528 CREATE INDEX \u8bed\u53e5\u521b\u5efa\u7d22\u5f15\uff1a CREATE INDEX name_index ON table_name(column_name); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a name_index \u662f\u7d22\u5f15\u7684\u540d\u79f0\u3002 table_name \u662f\u8981\u4e3a\u5176\u521b\u5efa\u7d22\u5f15\u7684\u8868\u3002 column_name \u662f\u8981\u521b\u5efa\u7d22\u5f15\u7684\u5217\u3002 2. \u7d22\u5f15\u7c7b\u578b MySQL \u652f\u6301\u591a\u79cd\u7d22\u5f15\u7c7b\u578b\uff0c\u5305\u62ec\uff1a \u666e\u901a\u7d22\u5f15\uff1a\u6700\u5e38\u89c1\u7684\u7d22\u5f15\u7c7b\u578b\uff0c\u52a0\u5feb\u5bf9\u5217\u7684\u67e5\u627e\u3002 \u552f\u4e00\u7d22\u5f15\uff1a\u4e0e\u666e\u901a\u7d22\u5f15\u7c7b\u4f3c\uff0c\u4f46\u786e\u4fdd\u5217\u4e2d\u7684\u503c\u552f\u4e00\u3002 \u5168\u6587\u7d22\u5f15\uff1a\u7528\u4e8e\u5728\u6587\u672c\u5217\u4e2d\u8fdb\u884c\u5168\u6587\u641c\u7d22\u3002 \u7a7a\u95f4\u7d22\u5f15\uff1a\u7528\u4e8e\u5728\u7a7a\u95f4\u6570\u636e\uff08\u5982\uff09\u4e2d\u8fdb\u884c\u67e5\u8be2\u3002 3. \u4f18\u5316\u7d22\u5f15\u4f7f\u7528 \u4e3a\u4e86\u4f18\u5316\u7d22\u5f15\u4f7f\u7528\uff0c\u53ef\u4ee5\u9075\u5faa\u4ee5\u4e0b\u51c6\u5219\uff1a \u53ea\u4e3a\u7ecf\u5e38\u67e5\u8be2\u7684\u5217\u521b\u5efa\u7d22\u5f15\u3002 \u9009\u62e9\u67e5\u8be2\u4e2d\u9891\u7e41\u4f7f\u7528\u7684\u5217\u4f5c\u4e3a\u7d22\u5f15\u5217\u3002 \u907f\u514d\u5728\u4e0d\u65ad\u66f4\u65b0\u7684\u5217\u4e0a\u521b\u5efa\u7d22\u5f15\u3002 \u5b9a\u671f\u4f7f\u7528 ANALYZE \u547d\u4ee4\u66f4\u65b0\u7d22\u5f15\u7edf\u8ba1\u4fe1\u606f\u3002 4. \u5220\u9664\u7d22\u5f15 \u5982\u679c\u4e0d\u518d\u9700\u8981\u7d22\u5f15\uff0c\u53ef\u4ee5\u4f7f\u7528 DROP INDEX \u8bed\u53e5\u5c06\u5176\u5220\u9664\uff1a DROP INDEX name_index ON table_name; \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5129","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5129"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5129\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}