{"id":6318,"date":"2024-11-14T08:57:41","date_gmt":"2024-11-14T00:57:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6318\/"},"modified":"2024-11-14T08:57:41","modified_gmt":"2024-11-14T00:57:41","slug":"mysql%e7%b4%a2%e5%bc%95%e6%98%af%e5%b9%b2%e5%98%9b%e7%9a%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6318\/","title":{"rendered":"mysql\u7d22\u5f15\u662f\u5e72\u561b\u7684"},"content":{"rendered":"<blockquote><p>\n  mysql \u7d22\u5f15\u662f\u52a0\u901f\u6570\u636e\u8bbf\u95ee\u7684\u6570\u636e\u7ed3\u6784\uff0c\u901a\u8fc7\u6709\u5e8f\u5217\u8868\u52a0\u5feb\u68c0\u7d22\u548c\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\uff0c\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\uff0c\u652f\u6301\u552f\u4e00\u6027\u7ea6\u675f\u3002\u7d22\u5f15\u7c7b\u578b\u5305\u62ec b-tree \u7d22\u5f15\u3001\u54c8\u5e0c\u7d22\u5f15\u3001\u5168\u6587\u7d22\u5f15\u548c\u7a7a\u95f4\u7d22\u5f15\u3002\u521b\u5efa\u7d22\u5f15\u4ee5\u4f18\u5316\u6570\u636e\u68c0\u7d22\uff0c\u7ba1\u7406\u7d22\u5f15\u4ee5\u7ef4\u6301\u6570\u636e\u5e93\u6027\u80fd\uff0c\u5305\u62ec\u76d1\u63a7\u4f7f\u7528\u60c5\u51b5\u548c\u5220\u9664\u4e0d\u5fc5\u8981\u7684\u7d22\u5f15\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202407\/31\/2024073122285955285.jpg\" class=\"aligncenter\" title=\"mysql\u7d22\u5f15\u662f\u5e72\u561b\u7684\u63d2\u56fe\" alt=\"mysql\u7d22\u5f15\u662f\u5e72\u561b\u7684\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u7d22\u5f15\u6982\u8ff0<\/strong><\/p>\n<p>MySQL \u7684\u7d22\u5f15\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u52a0\u901f\u5bf9\u6570\u636e\u5e93\u8868\u4e2d\u6570\u636e\u7684\u8bbf\u95ee\u3002<\/p>\n<p><strong>\u4f5c\u7528<\/strong><\/p>\n<p>\u7d22\u5f15\u901a\u8fc7\u521b\u5efa\u8868\u5217\u6216\u7ec4\u5408\u5217\u7684\u6709\u5e8f\u5217\u8868\uff0c\u5b9e\u73b0\u4ee5\u4e0b\u529f\u80fd\uff1a<\/p>\n<ul>\n<li> <strong>\u52a0\u5feb\u6570\u636e\u68c0\u7d22\uff1a<\/strong>\u5141\u8bb8\u6570\u636e\u5e93\u5feb\u901f\u5b9a\u4f4d\u6570\u636e\uff0c\u800c\u65e0\u9700\u626b\u63cf\u6574\u4e2a\u8868\u3002<\/li>\n<li> <strong>\u63d0\u5347\u67e5\u8be2\u6548\u7387\uff1a<\/strong>\u7d22\u5f15\u53ef\u4ee5\u6781\u5927\u5730\u63d0\u9ad8\u6d89\u53ca\u641c\u7d22\u7279\u5b9a\u503c\u7684\u67e5\u8be2\u7684\u901f\u5ea6\u3002<\/li>\n<li> <strong>\u7a7a\u95f4\u6362\u65f6\u95f4\uff1a<\/strong>\u4f7f\u7528\u7d22\u5f15\u4f1a\u5360\u7528\u989d\u5916\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u4f46\u53ef\u4ee5\u8282\u7701\u67e5\u8be2\u65f6\u95f4\u3002<\/li>\n<li> <strong>\u652f\u6301\u552f\u4e00\u6027\u7ea6\u675f\uff1a<\/strong>\u53ef\u4ee5\u5c06\u7d22\u5f15\u7528\u4e8e\u521b\u5efa\u552f\u4e00\u7ea6\u675f\uff0c\u786e\u4fdd\u8868\u4e2d\u6ca1\u6709\u91cd\u590d\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u7c7b\u578b<\/strong><\/p>\n<p>MySQL \u652f\u6301\u591a\u79cd\u7d22\u5f15\u7c7b\u578b\uff0c\u6bcf\u79cd\u7c7b\u578b\u90fd\u9002\u7528\u4e8e\u7279\u5b9a\u76ee\u7684\uff1a<\/p>\n<ul>\n<li> <strong>B-Tree \u7d22\u5f15\uff1a<\/strong>\u6700\u5e38\u89c1\u7684\u7d22\u5f15\u7c7b\u578b\uff0c\u7528\u4e8e\u6240\u6709\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<li> <strong>\u54c8\u5e0c\u7d22\u5f15\uff1a<\/strong>\u9488\u5bf9\u76f8\u7b49\u67e5\u627e\u8fdb\u884c\u4e86\u4f18\u5316\uff0c\u4f46\u65e0\u6cd5\u652f\u6301\u8303\u56f4\u67e5\u8be2\u3002<\/li>\n<li> <strong>\u5168\u6587\u7d22\u5f15\uff1a<\/strong>\u7528\u4e8e\u5728\u6587\u672c\u5217\u4e2d\u641c\u7d22\u5355\u8bcd\u6216\u77ed\u8bed\u3002<\/li>\n<li> <strong>\u7a7a\u95f4\u7d22\u5f15\uff1a<\/strong>\u7528\u4e8e\u5728\u5177\u6709\u7a7a\u95f4\u6570\u636e\u7684\u8868\u4e2d\u8fdb\u884c\u5730\u7406\u7a7a\u95f4\u641c\u7d22\u3002<\/li>\n<\/ul>\n<p><strong>\u521b\u5efa\u548c\u4f7f\u7528<\/strong><\/p>\n<p>\u8981\u521b\u5efa\u7d22\u5f15\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>ALTER TABLE table_name ADD INDEX index_name (column_name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u4f7f\u7528\u7d22\u5f15\uff0c\u8bf7\u5728\u67e5\u8be2\u4e2d\u6307\u5b9a\u7d22\u5f15\u7684\u5217\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>SELECT * FROM table_name WHERE column_name = value USE INDEX (index_name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7ba1\u7406\u7d22\u5f15<\/strong><\/p>\n<p>\u7ba1\u7406\u7d22\u5f15\u5bf9\u4e8e\u4f18\u5316\u6570\u636e\u5e93\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002\u5b9a\u671f\u76d1\u63a7\u7d22\u5f15\u7684\u4f7f\u7528\u60c5\u51b5\u5e76\u5220\u9664\u4e0d\u518d\u9700\u8981\u7684\u7d22\u5f15\u975e\u5e38\u91cd\u8981\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7ba1\u7406\u7d22\u5f15\uff1a<\/p>\n<ul>\n<li>SHOW INDEX FROM table_name\uff1a\u663e\u793a\u8868\u7684\u7d22\u5f15<\/li>\n<li>ALTER TABLE table_name DROP INDEX index_name\uff1a\u5220\u9664\u7d22\u5f15<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u7d22\u5f15\u662f\u5e72\u561b\u7684\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>mysql \u7d22\u5f15\u662f\u52a0\u901f\u6570\u636e\u8bbf\u95ee\u7684\u6570\u636e\u7ed3\u6784\uff0c\u901a\u8fc7\u6709\u5e8f\u5217\u8868\u52a0\u5feb\u68c0\u7d22\u548c\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\uff0c\u4ee5\u7a7a\u95f4\u6362\u65f6\u95f4\uff0c\u652f\u6301\u552f\u4e00\u6027\u7ea6\u675f\u3002\u7d22\u5f15\u7c7b\u578b\u5305\u62ec b-tree \u7d22\u5f15\u3001\u54c8\u5e0c\u7d22\u5f15\u3001\u5168\u6587\u7d22\u5f15\u548c\u7a7a\u95f4\u7d22\u5f15\u3002\u521b\u5efa\u7d22\u5f15\u4ee5\u4f18\u5316\u6570\u636e\u68c0\u7d22\uff0c\u7ba1\u7406\u7d22\u5f15\u4ee5\u7ef4\u6301\u6570\u636e\u5e93\u6027\u80fd\uff0c\u5305\u62ec\u76d1\u63a7\u4f7f\u7528\u60c5\u51b5\u548c\u5220\u9664\u4e0d\u5fc5\u8981\u7684\u7d22\u5f15\u3002 MySQL \u7d22\u5f15\u6982\u8ff0 MySQL \u7684\u7d22\u5f15\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u7528\u4e8e\u52a0\u901f\u5bf9\u6570\u636e\u5e93\u8868\u4e2d\u6570\u636e\u7684\u8bbf\u95ee\u3002 \u4f5c\u7528 \u7d22\u5f15\u901a\u8fc7\u521b\u5efa\u8868\u5217\u6216\u7ec4\u5408\u5217\u7684\u6709\u5e8f\u5217\u8868\uff0c\u5b9e\u73b0\u4ee5\u4e0b\u529f\u80fd\uff1a \u52a0\u5feb\u6570\u636e\u68c0\u7d22\uff1a\u5141\u8bb8\u6570\u636e\u5e93\u5feb\u901f\u5b9a\u4f4d\u6570\u636e\uff0c\u800c\u65e0\u9700\u626b\u63cf\u6574\u4e2a\u8868\u3002 \u63d0\u5347\u67e5\u8be2\u6548\u7387\uff1a\u7d22\u5f15\u53ef\u4ee5\u6781\u5927\u5730\u63d0\u9ad8\u6d89\u53ca\u641c\u7d22\u7279\u5b9a\u503c\u7684\u67e5\u8be2\u7684\u901f\u5ea6\u3002 \u7a7a\u95f4\u6362\u65f6\u95f4\uff1a\u4f7f\u7528\u7d22\u5f15\u4f1a\u5360\u7528\u989d\u5916\u7684\u5b58\u50a8\u7a7a\u95f4\uff0c\u4f46\u53ef\u4ee5\u8282\u7701\u67e5\u8be2\u65f6\u95f4\u3002 \u652f\u6301\u552f\u4e00\u6027\u7ea6\u675f\uff1a\u53ef\u4ee5\u5c06\u7d22\u5f15\u7528\u4e8e\u521b\u5efa\u552f\u4e00\u7ea6\u675f\uff0c\u786e\u4fdd\u8868\u4e2d\u6ca1\u6709\u91cd\u590d\u503c\u3002 \u7c7b\u578b MySQL \u652f\u6301\u591a\u79cd\u7d22\u5f15\u7c7b\u578b\uff0c\u6bcf\u79cd\u7c7b\u578b\u90fd\u9002\u7528\u4e8e\u7279\u5b9a\u76ee\u7684\uff1a B-Tree \u7d22\u5f15\uff1a\u6700\u5e38\u89c1\u7684\u7d22\u5f15\u7c7b\u578b\uff0c\u7528\u4e8e\u6240\u6709\u6570\u636e\u7c7b\u578b\u3002 \u54c8\u5e0c\u7d22\u5f15\uff1a\u9488\u5bf9\u76f8\u7b49\u67e5\u627e\u8fdb\u884c\u4e86\u4f18\u5316\uff0c\u4f46\u65e0\u6cd5\u652f\u6301\u8303\u56f4\u67e5\u8be2\u3002 \u5168\u6587\u7d22\u5f15\uff1a\u7528\u4e8e\u5728\u6587\u672c\u5217\u4e2d\u641c\u7d22\u5355\u8bcd\u6216\u77ed\u8bed\u3002 \u7a7a\u95f4\u7d22\u5f15\uff1a\u7528\u4e8e\u5728\u5177\u6709\u7a7a\u95f4\u6570\u636e\u7684\u8868\u4e2d\u8fdb\u884c\u5730\u7406\u7a7a\u95f4\u641c\u7d22\u3002 \u521b\u5efa\u548c\u4f7f\u7528 \u8981\u521b\u5efa\u7d22\u5f15\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a ALTER TABLE table_name ADD INDEX index_name (column_name); \u767b\u5f55\u540e\u590d\u5236 \u8981\u4f7f\u7528\u7d22\u5f15\uff0c\u8bf7\u5728\u67e5\u8be2\u4e2d\u6307\u5b9a\u7d22\u5f15\u7684\u5217\uff0c\u4f8b\u5982\uff1a SELECT * FROM table_name WHERE column_name = value USE INDEX (index_name); \u767b\u5f55\u540e\u590d\u5236 \u7ba1\u7406\u7d22\u5f15 \u7ba1\u7406\u7d22\u5f15\u5bf9\u4e8e\u4f18\u5316\u6570\u636e\u5e93\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002\u5b9a\u671f\u76d1\u63a7\u7d22\u5f15\u7684\u4f7f\u7528\u60c5\u51b5\u5e76\u5220\u9664\u4e0d\u518d\u9700\u8981\u7684\u7d22\u5f15\u975e\u5e38\u91cd\u8981\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7ba1\u7406\u7d22\u5f15\uff1a SHOW INDEX FROM table_name\uff1a\u663e\u793a\u8868\u7684\u7d22\u5f15 ALTER TABLE table_name DROP [&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-6318","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6318","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=6318"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6318\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}