{"id":26599,"date":"2024-11-24T08:54:01","date_gmt":"2024-11-24T00:54:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26599\/"},"modified":"2024-11-24T08:54:01","modified_gmt":"2024-11-24T00:54:01","slug":"%e5%a6%82%e4%bd%95%e5%87%86%e7%a1%ae%e6%9f%a5%e7%9c%8b-mysql-%e7%b4%a2%e5%bc%95%e7%9a%84%e7%a3%81%e7%9b%98%e7%a9%ba%e9%97%b4%e5%8d%a0%e7%94%a8%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26599\/","title":{"rendered":"\u5982\u4f55\u51c6\u786e\u67e5\u770b MySQL \u7d22\u5f15\u7684\u78c1\u76d8\u7a7a\u95f4\u5360\u7528\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173102635284953.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u51c6\u786e\u67e5\u770b MySQL \u7d22\u5f15\u7684\u78c1\u76d8\u7a7a\u95f4\u5360\u7528\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u51c6\u786e\u67e5\u770b MySQL \u7d22\u5f15\u7684\u78c1\u76d8\u7a7a\u95f4\u5360\u7528\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6316\u6398  \u7d22\u5f15\u7684\u78c1\u76d8\u8db3\u8ff9<\/strong><\/p>\n<p>\u5728 mysql \u4e2d\u7ba1\u7406\u7d22\u5f15\u5927\u5c0f\u662f\u6570\u636e\u5e93\u4f18\u5316\u4e2d\u7684\u5173\u952e\u65b9\u9762\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cshow table status; \u547d\u4ee4\u4ec5\u663e\u793a\u6240\u6709\u7d22\u5f15\u7684\u7d2f\u79ef\u5927\u5c0f\u3002\u4f46\u662f\uff0c\u5982\u679c\u60a8\u9700\u8981\u51c6\u786e\u4e86\u89e3\u6bcf\u4e2a\u7d22\u5f15\u7684\u78c1\u76d8\u6d88\u8017\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u4f7f\u7528\u9644\u52a0\u5b58\u50a8\u8fc7\u7a0b<\/strong><\/p>\n<pre>call mysql.innodb_index_stats(database(), table_name());<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u5b58\u50a8\u8fc7\u7a0b\u63d0\u4f9b\u4e86\u6709\u5173\u6bcf\u4e2a\u7d22\u5f15\u7684\u8be6\u7ec6\u7edf\u8ba1\u4fe1\u606f\uff0c\u5305\u62ec\u5927\u5c0f\u548c\u5197\u4f59\u3002<\/p>\n<p><strong>\u5229\u7528 information_schema<\/strong><\/p>\n<pre>select table_schema, table_name, index_name, round(index_length \/ power(1024, 2), 2) as index_size_mb\nfrom information_schema.innodb_indexes\nwhere table_schema = 'your_database_name' and table_name = 'your_table_name';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u67e5\u8be2\u63d0\u4f9b\u6bcf\u4e2a\u7d22\u5f15\u7684\u78c1\u76d8\u5927\u5c0f\uff08\u5355\u4f4d\u4e3a mb\uff09\u3002<\/p>\n<p><strong>\u501f\u52a9 show index<\/strong><\/p>\n<pre>SHOW INDEX FROM TABLE_NAME;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u547d\u4ee4\u663e\u793a\u6bcf\u4e2a\u7d22\u5f15\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u957f\u5ea6\u5217\uff0c\u8be5\u5217\u6307\u793a\u7d22\u5f15\u5360\u7528\u7684\u78c1\u76d8\u7a7a\u95f4\u5927\u5c0f\uff08\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\uff09\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<p>\u8bf7\u6ce8\u610f\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u80fd\u4e0d\u9002\u7528\u4e8e\u6240\u6709 mysql \u7248\u672c\u3002\u5efa\u8bae\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u6d4b\u8bd5\u8fd9\u4e9b\u65b9\u6cd5\u4e4b\u524d\u5148\u5728\u6d4b\u8bd5\u73af\u5883\u4e2d\u5c1d\u8bd5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u51c6\u786e\u67e5\u770b MySQL \u7d22\u5f15\u7684\u78c1\u76d8\u7a7a\u95f4\u5360\u7528\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6316\u6398 \u7d22\u5f15\u7684\u78c1\u76d8\u8db3\u8ff9 \u5728 mysql \u4e2d\u7ba1\u7406\u7d22\u5f15\u5927\u5c0f\u662f\u6570\u636e\u5e93\u4f18\u5316\u4e2d\u7684\u5173\u952e\u65b9\u9762\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cshow table status; \u547d\u4ee4\u4ec5\u663e\u793a\u6240\u6709\u7d22\u5f15\u7684\u7d2f\u79ef\u5927\u5c0f\u3002\u4f46\u662f\uff0c\u5982\u679c\u60a8\u9700\u8981\u51c6\u786e\u4e86\u89e3\u6bcf\u4e2a\u7d22\u5f15\u7684\u78c1\u76d8\u6d88\u8017\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u4f7f\u7528\u9644\u52a0\u5b58\u50a8\u8fc7\u7a0b call mysql.innodb_index_stats(database(), table_name()); \u767b\u5f55\u540e\u590d\u5236 \u6b64\u5b58\u50a8\u8fc7\u7a0b\u63d0\u4f9b\u4e86\u6709\u5173\u6bcf\u4e2a\u7d22\u5f15\u7684\u8be6\u7ec6\u7edf\u8ba1\u4fe1\u606f\uff0c\u5305\u62ec\u5927\u5c0f\u548c\u5197\u4f59\u3002 \u5229\u7528 information_schema select table_schema, table_name, index_name, round(index_length \/ power(1024, 2), 2) as index_size_mb from information_schema.innodb_indexes where table_schema = &#8216;your_database_name&#8217; and table_name = &#8216;your_table_name&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u67e5\u8be2\u63d0\u4f9b\u6bcf\u4e2a\u7d22\u5f15\u7684\u78c1\u76d8\u5927\u5c0f\uff08\u5355\u4f4d\u4e3a mb\uff09\u3002 \u501f\u52a9 show index SHOW INDEX FROM TABLE_NAME; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u547d\u4ee4\u663e\u793a\u6bcf\u4e2a\u7d22\u5f15\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u957f\u5ea6\u5217\uff0c\u8be5\u5217\u6307\u793a\u7d22\u5f15\u5360\u7528\u7684\u78c1\u76d8\u7a7a\u95f4\u5927\u5c0f\uff08\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\uff09\u3002 \u6ce8\u610f\uff1a \u8bf7\u6ce8\u610f\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u80fd\u4e0d\u9002\u7528\u4e8e\u6240\u6709 mysql \u7248\u672c\u3002\u5efa\u8bae\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u6d4b\u8bd5\u8fd9\u4e9b\u65b9\u6cd5\u4e4b\u524d\u5148\u5728\u6d4b\u8bd5\u73af\u5883\u4e2d\u5c1d\u8bd5\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u51c6\u786e\u67e5\u770b MySQL [&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-26599","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26599","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=26599"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26599\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}