{"id":5227,"date":"2024-11-14T10:21:04","date_gmt":"2024-11-14T02:21:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5227\/"},"modified":"2024-11-14T10:21:04","modified_gmt":"2024-11-14T02:21:04","slug":"mysql%e6%80%8e%e4%b9%88%e6%8d%a2%e5%88%97%e5%90%8d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5227\/","title":{"rendered":"mysql\u600e\u4e48\u6362\u5217\u540d"},"content":{"rendered":"<blockquote><p>\n  \u901a\u8fc7\u4f7f\u7528 alter table \u8bed\u53e5\u7684 rename column \u5b50\u53e5\uff0c\u53ef\u4ee5\u4fee\u6539 mysql \u8868\u4e2d\u7684\u5217\u540d\u3002\u6b65\u9aa4\u5982\u4e0b\uff1a\u6307\u5b9a\u8981\u4fee\u6539\u7684\u8868\u540d\u3002\u6307\u5b9a\u8981\u91cd\u547d\u540d\u7684\u65e7\u5217\u540d\u3002\u6307\u5b9a\u8981\u4f7f\u7528\u7684\u65b0\u7684\u5217\u540d\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/26\/2024052617032147466.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u6362\u5217\u540d\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u6362\u5217\u540d\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4fee\u6539 MySQL \u8868\u7684\u5217\u540d<\/strong><\/p>\n<p>\u5728 MySQL \u4e2d\uff0c\u4fee\u6539\u8868\u5217\u540d\u662f\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u6765\u5b9e\u73b0\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u5047\u8bbe\u6709\u4e00\u5f20\u540d\u4e3a users \u7684\u8868\uff0c\u5305\u542b\u4e00\u4e2a\u540d\u4e3a first_name \u7684\u5217\uff0c\u6211\u4eec\u5e0c\u671b\u5c06\u5176\u540d\u79f0\u66f4\u6539\u4e3a name\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>ALTER TABLE users RENAME COLUMN first_name TO name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6267\u884c\u6b64\u8bed\u53e5\u540e\uff0cfirst_name \u5217\u7684\u540d\u79f0\u5c06\u66f4\u6539\u4e3a name\u3002<\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u65b0\u5217\u540d\u5728\u8868\u4e2d\u662f\u552f\u4e00\u7684\u3002<\/li>\n<li>\u4fee\u6539\u5217\u540d\u4e0d\u4f1a\u5f71\u54cd\u5b58\u50a8\u5728\u5217\u4e2d\u7684\u6570\u636e\u3002<\/li>\n<li>\u5982\u679c\u5217\u540d\u662f\u5916\u952e\u7ea6\u675f\u7684\u4e00\u90e8\u5206\uff0c\u5219\u9700\u8981\u4fee\u6539\u7ea6\u675f\u4ee5\u53cd\u6620\u65b0\u540d\u79f0\u3002<\/li>\n<li>\u5982\u679c\u8868\u4e2d\u6709\u89e6\u53d1\u5668\u6216\u5b58\u50a8\u8fc7\u7a0b\u4f9d\u8d56\u4e8e\u65e7\u5217\u540d\uff0c\u5219\u9700\u8981\u4fee\u6539\u8fd9\u4e9b\u5bf9\u8c61\u4ee5\u53cd\u6620\u65b0\u540d\u79f0\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u6362\u5217\u540d\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>\u901a\u8fc7\u4f7f\u7528 alter table \u8bed\u53e5\u7684 rename column \u5b50\u53e5\uff0c\u53ef\u4ee5\u4fee\u6539 mysql \u8868\u4e2d\u7684\u5217\u540d\u3002\u6b65\u9aa4\u5982\u4e0b\uff1a\u6307\u5b9a\u8981\u4fee\u6539\u7684\u8868\u540d\u3002\u6307\u5b9a\u8981\u91cd\u547d\u540d\u7684\u65e7\u5217\u540d\u3002\u6307\u5b9a\u8981\u4f7f\u7528\u7684\u65b0\u7684\u5217\u540d\u3002 \u5982\u4f55\u4fee\u6539 MySQL \u8868\u7684\u5217\u540d \u5728 MySQL \u4e2d\uff0c\u4fee\u6539\u8868\u5217\u540d\u662f\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u6765\u5b9e\u73b0\u3002 \u8bed\u6cd5\uff1a ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name; \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a \u5047\u8bbe\u6709\u4e00\u5f20\u540d\u4e3a users \u7684\u8868\uff0c\u5305\u542b\u4e00\u4e2a\u540d\u4e3a first_name \u7684\u5217\uff0c\u6211\u4eec\u5e0c\u671b\u5c06\u5176\u540d\u79f0\u66f4\u6539\u4e3a name\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a ALTER TABLE users RENAME COLUMN first_name TO name; \u767b\u5f55\u540e\u590d\u5236 \u6267\u884c\u6b64\u8bed\u53e5\u540e\uff0cfirst_name \u5217\u7684\u540d\u79f0\u5c06\u66f4\u6539\u4e3a name\u3002 \u6ce8\u610f\u4e8b\u9879\uff1a \u786e\u4fdd\u65b0\u5217\u540d\u5728\u8868\u4e2d\u662f\u552f\u4e00\u7684\u3002 \u4fee\u6539\u5217\u540d\u4e0d\u4f1a\u5f71\u54cd\u5b58\u50a8\u5728\u5217\u4e2d\u7684\u6570\u636e\u3002 \u5982\u679c\u5217\u540d\u662f\u5916\u952e\u7ea6\u675f\u7684\u4e00\u90e8\u5206\uff0c\u5219\u9700\u8981\u4fee\u6539\u7ea6\u675f\u4ee5\u53cd\u6620\u65b0\u540d\u79f0\u3002 \u5982\u679c\u8868\u4e2d\u6709\u89e6\u53d1\u5668\u6216\u5b58\u50a8\u8fc7\u7a0b\u4f9d\u8d56\u4e8e\u65e7\u5217\u540d\uff0c\u5219\u9700\u8981\u4fee\u6539\u8fd9\u4e9b\u5bf9\u8c61\u4ee5\u53cd\u6620\u65b0\u540d\u79f0\u3002 \u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u6362\u5217\u540d\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5227","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5227","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=5227"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5227\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}