{"id":25388,"date":"2024-11-24T09:51:43","date_gmt":"2024-11-24T01:51:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25388\/"},"modified":"2024-11-24T09:51:43","modified_gmt":"2024-11-24T01:51:43","slug":"mysql-%e7%bb%88%e7%ab%af%ef%bc%9a%e6%9b%b4%e6%94%b9%e8%a1%a8%e3%80%81%e5%ad%97%e7%ac%a6%e9%9b%86%e5%92%8c%e5%88%a0%e9%99%a4-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25388\/","title":{"rendered":"MySQL \u7ec8\u7aef\uff1a\u66f4\u6539\u8868\u3001\u5b57\u7b26\u96c6\u548c\u5220\u9664"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173060466838692.jpg\" class=\"aligncenter\" title=\"MySQL \u7ec8\u7aef\uff1a\u66f4\u6539\u8868\u3001\u5b57\u7b26\u96c6\u548c\u5220\u9664\u63d2\u56fe\" alt=\"MySQL \u7ec8\u7aef\uff1a\u66f4\u6539\u8868\u3001\u5b57\u7b26\u96c6\u548c\u5220\u9664\u63d2\u56fe\" \/><\/p>\n<h2> \u4fee\u6539\u8868 <\/h2>\n<p> \u4e2d\u5e26\u6709 modify \u5b50\u53e5\u7684 alter table \u547d\u4ee4\u7528\u4e8e\u66f4\u6539\u8868\u4e2d\u73b0\u6709\u5217\u7684\u5b9a\u4e49\u3002\u547d\u4ee4\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<pre>alter table table_name modify column_name data_type [options];\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> table_name: \u6b63\u5728\u4fee\u6539\u5217\u7684\u8868\u7684\u540d\u79f0\u3002<\/li>\n<li> column_name\uff1a\u8981\u4fee\u6539\u7684\u5217\u7684\u540d\u79f0\u3002<\/li>\n<li> data_type\uff1a\u5217\u7684\u65b0\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<li> [options]\uff1a\u4efb\u4f55\u5176\u4ed6\u53ef\u9009\u89c4\u8303\uff0c\u4f8b\u5982 not null\u3001default \u503c\u7b49<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe users \u8868\u4e2d\u6709\u4e00\u4e2a int \u7c7b\u578b\u7684\u5e74\u9f84\u5217\uff0c\u5e76\u4e14\u60a8\u60f3\u5c06\u5176\u66f4\u6539\u4e3a int(3)\uff0c\u9ed8\u8ba4\u503c\u4e3a 18\u3002\u547d\u4ee4\u4e3a\uff1a<\/p>\n<pre>alter table users modify age int(3) default 18;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u547d\u4ee4\u5c06age\u5217\u7684\u6570\u636e\u7c7b\u578b\u66f4\u6539\u4e3aint(3)\uff0c\u5e76\u5c06\u9ed8\u8ba4\u503c\u8bbe\u7f6e\u4e3a18\u3002<\/p>\n<h2> \u66f4\u6539\u8868\u66f4\u6539 <\/h2>\n<p>mysql \u4e2d\u5e26\u6709 change \u5b50\u53e5\u7684 alter table \u547d\u4ee4\u7528\u4e8e\u91cd\u547d\u540d\u5217\u5e76\u66f4\u6539\u5176\u6570\u636e\u7c7b\u578b\u6216\u5c5e\u6027\u3002\u547d\u4ee4\u7684\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<pre>alter table table_name change old_column_name new_column_name data_type [options];\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> table_name: \u5217\u6240\u5728\u8868\u7684\u540d\u79f0\u3002<\/li>\n<li> old_column_name\uff1a\u8981\u4fee\u6539\u7684\u5217\u7684\u5f53\u524d\u540d\u79f0\u3002<\/li>\n<li> new_column_name\uff1a\u5217\u7684\u65b0\u540d\u79f0\u3002<\/li>\n<li> data_type\uff1a\u5217\u7684\u65b0\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<li> [\u9009\u9879]\uff1a\u4efb\u4f55\u9644\u52a0\u89c4\u8303\uff0c\u4f8b\u5982 not null\u3001default \u503c\u7b49<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe users \u8868\u4e2d\u6709\u4e00\u4e2a\u7c7b\u578b\u4e3a int \u7684 age \u5217\uff0c\u5e76\u4e14\u60a8\u60f3\u5c06\u5176\u91cd\u547d\u540d\u4e3a current_age \u5e76\u5c06\u5176\u66f4\u6539\u4e3a int(3)\uff0c\u9ed8\u8ba4\u503c\u4e3a 18\u3002\u547d\u4ee4\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>alter table users change age current_age int(3) default 18;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u547d\u4ee4\u5c06age\u5217\u91cd\u547d\u540d\u4e3acurrent_age\uff0c\u5c06\u5176\u6570\u636e\u7c7b\u578b\u66f4\u6539\u4e3aint(3)\uff0c\u5e76\u5c06\u9ed8\u8ba4\u503c\u8bbe\u7f6e\u4e3a18\u3002<\/p>\n<h2> \u66f4\u6539\u8868\u91cd\u547d\u540d\u4e3a <\/h2>\n<p>mysql \u4e2d\u5e26\u6709 rename to \u5b50\u53e5\u7684 alter table \u547d\u4ee4\u7528\u4e8e\u91cd\u547d\u540d\u8868\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>alter table old_table_name rename to new_table_name;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> old_table_name\uff1a\u8981\u91cd\u547d\u540d\u7684\u8868\u7684\u5f53\u524d\u540d\u79f0\u3002<\/li>\n<li> new_table_name\uff1a\u8868\u7684\u65b0\u540d\u79f0\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a users \u7684\u8868\uff0c\u5e76\u4e14\u60a8\u60f3\u5c06\u5176\u91cd\u547d\u540d\u4e3acustomers\u3002\u547d\u4ee4\u662f\uff1a<\/p>\n<pre>alter table users rename to customers;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u547d\u4ee4\u5c06\u8868 users \u91cd\u547d\u540d\u4e3acustomers\u3002<\/p>\n<h2> \u66f4\u6539\u8868\u8f6c\u6362\u4e3a\u5b57\u7b26\u96c6 <\/h2>\n<p>mysql \u4e2d\u7684 alter table &#8230; convert to character set \u547d\u4ee4\u7528\u4e8e\u66f4\u6539\u6574\u4e2a\u8868\u7684\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>alter table table_name convert to character set charset_name [collate collation_name];\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> table_name\uff1a\u8981\u66f4\u6539\u5176\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u7684\u8868\u7684\u540d\u79f0\u3002<\/li>\n<li> charset_name\uff1a\u8868\u7684\u65b0\u5b57\u7b26\u96c6\uff0c\u4f8b\u5982utf8mb4\u3002<\/li>\n<li> [collate collat\u200b\u200bion_name]\uff1a\u7528\u4e8e\u6307\u5b9a\u6392\u5e8f\u89c4\u5219\u7684\u53ef\u9009\u53c2\u6570\uff08\u4f8b\u5982 utf8mb4_unicode_ci\uff09\u3002\u5982\u679c\u7701\u7565\uff0c\u5c06\u4f7f\u7528\u6307\u5b9a\u5b57\u7b26\u96c6\u7684\u9ed8\u8ba4\u6392\u5e8f\u89c4\u5219\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u60f3\u5c06customers\u8868\u7684\u5b57\u7b26\u96c6\u66f4\u6539\u4e3autf8mb4\u53ca\u5176\u9ed8\u8ba4\u6392\u5e8f\u89c4\u5219\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre>alter table customers convert to character set utf8mb4;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6216\u8005\uff0c\u5982\u679c\u60a8\u60f3\u6307\u5b9a\u7279\u5b9a\u7684\u6392\u5e8f\u89c4\u5219\uff0c\u4f8b\u5982 utf8mb4_unicode_ci\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre>alter table customers convert to character set utf8mb4 collate utf8mb4_unicode_ci;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u547d\u4ee4\u5c06\u8868\u4e2d\u7684\u6240\u6709\u6587\u672c\u5217\u66f4\u65b0\u4e3a\u6307\u5b9a\u7684\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u3002<\/p>\n<h2> \u6389\u843d\u8868 <\/h2>\n<p>sql \u4e2d\u7684 drop table \u547d\u4ee4\u7528\u4e8e\u4ece\u6570\u636e\u5e93\u4e2d\u6c38\u4e45\u5220\u9664\u8868\u53ca\u5176\u6240\u6709\u6570\u636e\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>drop table table_name;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> table_name\uff1a\u8981\u5220\u9664\u7684\u8868\u7684\u540d\u79f0\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5982\u679c\u8981\u5220\u9664\u540d\u4e3acustomers\u7684\u8868\uff0c\u547d\u4ee4\u4e3a\uff1a<\/p>\n<pre>DROP TABLE customers;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<blockquote><p>\n  \u8b66\u544a\uff1a\u4f7f\u7528 drop table \u5c06\u6c38\u4e45\u5220\u9664\u8868\u53ca\u5176\u6240\u6709\u6570\u636e\u3002\u6b64\u64cd\u4f5c\u65e0\u6cd5\u64a4\u6d88\uff0c\u56e0\u6b64\u8bf7\u786e\u4fdd\u5728\u6267\u884c\u6b64\u547d\u4ee4\u4e4b\u524d\u5907\u4efd\u6240\u6709\u91cd\u8981\u6570\u636e\u3002\n<\/p><\/blockquote>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u7ec8\u7aef\uff1a\u66f4\u6539\u8868\u3001\u5b57\u7b26\u96c6\u548c\u5220\u9664\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>\u4fee\u6539\u8868 \u4e2d\u5e26\u6709 modify \u5b50\u53e5\u7684 alter table \u547d\u4ee4\u7528\u4e8e\u66f4\u6539\u8868\u4e2d\u73b0\u6709\u5217\u7684\u5b9a\u4e49\u3002\u547d\u4ee4\u7ed3\u6784\u5982\u4e0b\uff1a alter table table_name modify column_name data_type [options]; \u767b\u5f55\u540e\u590d\u5236 table_name: \u6b63\u5728\u4fee\u6539\u5217\u7684\u8868\u7684\u540d\u79f0\u3002 column_name\uff1a\u8981\u4fee\u6539\u7684\u5217\u7684\u540d\u79f0\u3002 data_type\uff1a\u5217\u7684\u65b0\u6570\u636e\u7c7b\u578b\u3002 [options]\uff1a\u4efb\u4f55\u5176\u4ed6\u53ef\u9009\u89c4\u8303\uff0c\u4f8b\u5982 not null\u3001default \u503c\u7b49 \u793a\u4f8b \u5047\u8bbe users \u8868\u4e2d\u6709\u4e00\u4e2a int \u7c7b\u578b\u7684\u5e74\u9f84\u5217\uff0c\u5e76\u4e14\u60a8\u60f3\u5c06\u5176\u66f4\u6539\u4e3a int(3)\uff0c\u9ed8\u8ba4\u503c\u4e3a 18\u3002\u547d\u4ee4\u4e3a\uff1a alter table users modify age int(3) default 18; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u547d\u4ee4\u5c06age\u5217\u7684\u6570\u636e\u7c7b\u578b\u66f4\u6539\u4e3aint(3)\uff0c\u5e76\u5c06\u9ed8\u8ba4\u503c\u8bbe\u7f6e\u4e3a18\u3002 \u66f4\u6539\u8868\u66f4\u6539 mysql \u4e2d\u5e26\u6709 change \u5b50\u53e5\u7684 alter table \u547d\u4ee4\u7528\u4e8e\u91cd\u547d\u540d\u5217\u5e76\u66f4\u6539\u5176\u6570\u636e\u7c7b\u578b\u6216\u5c5e\u6027\u3002\u547d\u4ee4\u7684\u7ed3\u6784\u5982\u4e0b\uff1a alter table table_name change old_column_name new_column_name [&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-25388","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25388","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=25388"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25388\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}