{"id":5163,"date":"2024-11-14T11:06:17","date_gmt":"2024-11-14T03:06:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5163\/"},"modified":"2024-11-14T11:06:17","modified_gmt":"2024-11-14T03:06:17","slug":"mysql%e5%88%86%e5%8c%ba%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5163\/","title":{"rendered":"mysql\u5206\u533a\u600e\u4e48\u8bbe\u7f6e"},"content":{"rendered":"<blockquote><p>\n  \u5206\u533a\u662f\u4e00\u79cd\u5c06\u5927\u578b\u6570\u636e\u5e93\u8868\u5206\u5272\u6210\u66f4\u5c0f\u90e8\u5206\u7684\u6280\u672f\uff0c\u4ee5\u63d0\u9ad8\u6027\u80fd\u3001\u53ef\u6269\u5c55\u6027\u3001\u53ef\u7528\u6027\u548c\u6570\u636e\u7ba1\u7406\u3002\u8bbe\u7f6e\u5206\u533a\u5305\u62ec\uff1a\u786e\u5b9a\u5206\u533a\u7b56\u7565\uff08\u8303\u56f4\u3001\u54c8\u5e0c\u6216\u5217\u8868\u5206\u533a\uff09\uff0c\u521b\u5efa\u5206\u533a\u8868\uff0c\u52a0\u8f7d\u6570\u636e\u4ee5\u53ca\u4f7f\u7528 alter table \u8bed\u53e5\u7ba1\u7406\u5206\u533a\uff08\u6dfb\u52a0\u3001\u5220\u9664\u548c\u5408\u5e76\uff09\u3002\u4f18\u52bf\u5305\u62ec\u67e5\u8be2\u6027\u80fd\u63d0\u5347\uff0c\u53ef\u6269\u5c55\u6027\u589e\u5f3a\uff0c\u53ef\u7528\u6027\u63d0\u9ad8\u4ee5\u53ca\u6570\u636e\u7ba1\u7406\u7b80\u5316\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/22\/2024052217572581718.jpg\" class=\"aligncenter\" title=\"mysql\u5206\u533a\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" alt=\"mysql\u5206\u533a\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u5206\u533a\u8bbe\u7f6e\u8be6\u89e3<\/strong><\/p>\n<p><strong>\u5206\u533a\u6709\u4ec0\u4e48\u7528\uff1f<\/strong><\/p>\n<p>\u5206\u533a\u662f\u4e00\u79cd\u5c06\u5927\u578b\u6570\u636e\u5e93\u8868\u5212\u5206\u4e3a\u591a\u4e2a\u66f4\u5c0f\u3001\u66f4\u6613\u4e8e\u7ba1\u7406\u7684\u90e8\u5206\u7684\u6280\u672f\u3002\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u6570\u636e\u5e93\u6027\u80fd\u3001\u53ef\u6269\u5c55\u6027\u548c\u53ef\u7528\u6027\u3002<\/p>\n<p><strong>\u5982\u4f55\u8bbe\u7f6e\u5206\u533a\uff1f<\/strong><\/p>\n<p><strong>1. \u786e\u5b9a\u5206\u533a\u7b56\u7565\uff1a<\/strong><\/p>\n<ul>\n<li>\u8303\u56f4\u5206\u533a\uff1a\u6309\u503c\u8303\u56f4\u5206\u5272\u6570\u636e\uff0c\u4f8b\u5982\u65e5\u671f\u8303\u56f4\u3002<\/li>\n<li>\u54c8\u5e0c\u5206\u533a\uff1a\u6309\u54c8\u5e0c\u503c\u5206\u5272\u6570\u636e\uff0c\u786e\u4fdd\u6570\u636e\u5747\u5300\u5206\u5e03\u3002<\/li>\n<li>\u5217\u8868\u5206\u533a\uff1a\u6309\u7279\u5b9a\u503c\u5217\u8868\u5206\u5272\u6570\u636e\u3002<\/li>\n<\/ul>\n<p><strong>2. \u521b\u5efa\u5206\u533a\u8868\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u5e76\u6307\u5b9a\u5206\u533a\u7b56\u7565\uff1a<\/p>\n<pre>CREATE TABLE partitioned_table (\n  id INT,\n  name VARCHAR(255),\n  date DATETIME\n) PARTITION BY RANGE (date) (\n  PARTITION p0 VALUES LESS THAN ('2023-01-01'),\n  PARTITION p1 VALUES LESS THAN ('2023-04-01'),\n  PARTITION p2 VALUES LESS THAN ('2023-07-01')\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u52a0\u8f7d\u6570\u636e\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 INSERT \u8bed\u53e5\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u5206\u533a\u8868\u4e2d\u3002MySQL \u4f1a\u81ea\u52a8\u5c06\u6570\u636e\u5206\u914d\u5230\u9002\u5f53\u7684\u5206\u533a\u3002<\/p>\n<p><strong>4. \u7ba1\u7406\u5206\u533a\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u6dfb\u52a0\u5206\u533a\uff1a<\/strong>\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u6dfb\u52a0\u65b0\u5206\u533a\u3002<\/li>\n<li> <strong>\u5220\u9664\u5206\u533a\uff1a<\/strong>\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u5220\u9664\u4e0d\u9700\u8981\u7684\u5206\u533a\u3002<\/li>\n<li> <strong>\u5408\u5e76\u5206\u533a\uff1a<\/strong>\u4f7f\u7528 OPTIMIZE TABLE \u8bed\u53e5\u5c06\u76f8\u90bb\u5206\u533a\u5408\u5e76\u6210\u4e00\u4e2a\u66f4\u5927\u7684\u5206\u533a\u3002<\/li>\n<\/ul>\n<p><strong>\u4f18\u52bf\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u6027\u80fd\u63d0\u5347\uff1a<\/strong>\u5206\u533a\u5141\u8bb8\u67e5\u8be2\u548c\u7d22\u5f15\u9488\u5bf9\u7279\u5b9a\u5206\u533a\uff0c\u4ece\u800c\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<li> <strong>\u53ef\u6269\u5c55\u6027\uff1a<\/strong>\u5206\u533a\u4f7f\u5f97\u5411\u6570\u636e\u5e93\u4e2d\u6dfb\u52a0\u66f4\u591a\u6570\u636e\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u6574\u4f53\u6027\u80fd\u3002<\/li>\n<li> <strong>\u53ef\u7528\u6027\uff1a<\/strong>\u5206\u533a\u5141\u8bb8\u5728\u6267\u884c\u7ef4\u62a4\u4efb\u52a1\u65f6\u53ea\u9501\u4f4f\u4e00\u4e2a\u5206\u533a\uff0c\u4ece\u800c\u63d0\u9ad8\u53ef\u7528\u6027\u3002<\/li>\n<li> <strong>\u6570\u636e\u7ba1\u7406\uff1a<\/strong>\u5206\u533a\u7b80\u5316\u4e86\u6570\u636e\u7684\u7ba1\u7406\u548c\u7ec4\u7ec7\uff0c\u5c24\u5176\u662f\u5728\u9700\u8981\u5904\u7406\u5927\u91cf\u6570\u636e\u65f6\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5206\u533a\u600e\u4e48\u8bbe\u7f6e\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>\u5206\u533a\u662f\u4e00\u79cd\u5c06\u5927\u578b\u6570\u636e\u5e93\u8868\u5206\u5272\u6210\u66f4\u5c0f\u90e8\u5206\u7684\u6280\u672f\uff0c\u4ee5\u63d0\u9ad8\u6027\u80fd\u3001\u53ef\u6269\u5c55\u6027\u3001\u53ef\u7528\u6027\u548c\u6570\u636e\u7ba1\u7406\u3002\u8bbe\u7f6e\u5206\u533a\u5305\u62ec\uff1a\u786e\u5b9a\u5206\u533a\u7b56\u7565\uff08\u8303\u56f4\u3001\u54c8\u5e0c\u6216\u5217\u8868\u5206\u533a\uff09\uff0c\u521b\u5efa\u5206\u533a\u8868\uff0c\u52a0\u8f7d\u6570\u636e\u4ee5\u53ca\u4f7f\u7528 alter table \u8bed\u53e5\u7ba1\u7406\u5206\u533a\uff08\u6dfb\u52a0\u3001\u5220\u9664\u548c\u5408\u5e76\uff09\u3002\u4f18\u52bf\u5305\u62ec\u67e5\u8be2\u6027\u80fd\u63d0\u5347\uff0c\u53ef\u6269\u5c55\u6027\u589e\u5f3a\uff0c\u53ef\u7528\u6027\u63d0\u9ad8\u4ee5\u53ca\u6570\u636e\u7ba1\u7406\u7b80\u5316\u3002 MySQL \u5206\u533a\u8bbe\u7f6e\u8be6\u89e3 \u5206\u533a\u6709\u4ec0\u4e48\u7528\uff1f \u5206\u533a\u662f\u4e00\u79cd\u5c06\u5927\u578b\u6570\u636e\u5e93\u8868\u5212\u5206\u4e3a\u591a\u4e2a\u66f4\u5c0f\u3001\u66f4\u6613\u4e8e\u7ba1\u7406\u7684\u90e8\u5206\u7684\u6280\u672f\u3002\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u6570\u636e\u5e93\u6027\u80fd\u3001\u53ef\u6269\u5c55\u6027\u548c\u53ef\u7528\u6027\u3002 \u5982\u4f55\u8bbe\u7f6e\u5206\u533a\uff1f 1. \u786e\u5b9a\u5206\u533a\u7b56\u7565\uff1a \u8303\u56f4\u5206\u533a\uff1a\u6309\u503c\u8303\u56f4\u5206\u5272\u6570\u636e\uff0c\u4f8b\u5982\u65e5\u671f\u8303\u56f4\u3002 \u54c8\u5e0c\u5206\u533a\uff1a\u6309\u54c8\u5e0c\u503c\u5206\u5272\u6570\u636e\uff0c\u786e\u4fdd\u6570\u636e\u5747\u5300\u5206\u5e03\u3002 \u5217\u8868\u5206\u533a\uff1a\u6309\u7279\u5b9a\u503c\u5217\u8868\u5206\u5272\u6570\u636e\u3002 2. \u521b\u5efa\u5206\u533a\u8868\uff1a \u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u5e76\u6307\u5b9a\u5206\u533a\u7b56\u7565\uff1a CREATE TABLE partitioned_table ( id INT, name VARCHAR(255), date DATETIME ) PARTITION BY RANGE (date) ( PARTITION p0 VALUES LESS THAN (&#8216;2023-01-01&#8217;), PARTITION p1 VALUES LESS THAN (&#8216;2023-04-01&#8217;), PARTITION p2 VALUES LESS THAN (&#8216;2023-07-01&#8217;) ); [&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-5163","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5163","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=5163"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5163\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}