{"id":5769,"date":"2024-11-14T10:37:57","date_gmt":"2024-11-14T02:37:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5769\/"},"modified":"2024-11-14T10:37:57","modified_gmt":"2024-11-14T02:37:57","slug":"mysql-default%e4%bb%80%e4%b9%88%e6%84%8f%e6%80%9d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5769\/","title":{"rendered":"mysql\u00a0default\u4ec0\u4e48\u610f\u601d"},"content":{"rendered":"<blockquote><p>\n  mysql \u4e2d\u7684 default \u5173\u952e\u5b57\u8bbe\u7f6e\u5217\u7684\u9ed8\u8ba4\u503c\uff0c\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3001\u7b80\u5316\u6570\u636e\u63d2\u5165\u548c\u63d0\u4f9b\u6570\u636e\u4e00\u81f4\u6027\u3002\u5b83\u53ef\u4e0e\u5217\u5b9a\u4e49\u4e00\u8d77\u4f7f\u7528\uff0c\u4f46\u4e0d\u53ef\u7528\u4e8e\u4e3b\u952e\u6216\u975e\u7a7a\u7ea6\u675f\u7684\u5217\u3001\u4e0d\u652f\u6301\u9ed8\u8ba4\u503c\u7684\u6570\u636e\u7c7b\u578b\u6216\u4e0d\u5339\u914d\u6570\u636e\u7c7b\u578b\u7684\u9ed8\u8ba4\u503c\u3002\u9ed8\u8ba4\u503c\u53ef\u4ee5\u662f\u5e38\u91cf\u3001\u8868\u8fbe\u5f0f\u6216\u5b50\u67e5\u8be2\u7684\u7ed3\u679c\uff0c\u5e76\u53ef\u4ee5\u5728\u521b\u5efa\u8868\u540e\u66f4\u6539\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/02\/2024060201042120181.jpg\" class=\"aligncenter\" title=\"mysql\u00a0default\u4ec0\u4e48\u610f\u601d\u63d2\u56fe\" alt=\"mysql\u00a0default\u4ec0\u4e48\u610f\u601d\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL DEFAULT \u542b\u4e49<\/strong><\/p>\n<p>MySQL \u4e2d\u7684 DEFAULT \u5173\u952e\u5b57\u7528\u4e8e\u8bbe\u7f6e\u4e00\u4e2a\u5217\u5728\u521b\u5efa\u8868\u65f6\u6ca1\u6709\u660e\u786e\u6307\u5b9a\u503c\u7684\u9ed8\u8ba4\u503c\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b9\u4fbf\u7684\u65b9\u5f0f\u6765\u786e\u4fdd\u5217\u5728\u6240\u6709\u60c5\u51b5\u4e0b\u90fd\u6709\u4e00\u4e2a\u503c\uff0c\u5373\u4f7f\u672a\u660e\u786e\u63d2\u5165\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 DEFAULT<\/strong><\/p>\n<p>DEFAULT \u5173\u952e\u5b57\u4e0e\u5217\u5b9a\u4e49\u4e00\u8d77\u4f7f\u7528\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>CREATE TABLE table_name (\n  column_name DATATYPE DEFAULT default_value\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u5f20\u5305\u542b\u4e00\u4e2a\u5177\u6709\u9ed8\u8ba4\u503c &#8220;Unknown&#8221; \u7684 &#8220;name&#8221; \u5217\u7684\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>CREATE TABLE users (\n  name VARCHAR(255) DEFAULT \"Unknown\"\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u9ed8\u8ba4\u503c\u7684\u4f5c\u7528<\/strong><\/p>\n<p>\u6307\u5b9a\u5217\u7684 DEFAULT \u503c\u6709\u51e0\u4e2a\u597d\u5904\uff1a<\/p>\n<ul>\n<li> <strong>\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\uff1a<\/strong>\u5b83\u9632\u6b62\u5217\u503c\u4e3a\u7a7a\u6216\u672a\u77e5\uff0c\u4ece\u800c\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002<\/li>\n<li> <strong>\u7b80\u5316\u6570\u636e\u63d2\u5165\uff1a<\/strong>\u5f53\u521b\u5efa\u65b0\u884c\u65f6\uff0c\u5982\u679c\u672a\u6307\u5b9a\u5217\u503c\uff0c\u5219\u4f7f\u7528\u9ed8\u8ba4\u503c\uff0c\u7b80\u5316\u4e86\u6570\u636e\u63d2\u5165\u8fc7\u7a0b\u3002<\/li>\n<li> <strong>\u63d0\u4f9b\u4e00\u81f4\u6027\uff1a<\/strong>\u5b83\u786e\u4fdd\u5217\u5728\u6240\u6709\u884c\u4e2d\u5177\u6709\u76f8\u540c\u7684\u503c\uff0c\u4ece\u800c\u63d0\u4f9b\u6570\u636e\u4e00\u81f4\u6027\u3002<\/li>\n<\/ul>\n<p><strong>\u7279\u6b8a\u60c5\u51b5<\/strong><\/p>\n<p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4e0d\u80fd\u4e3a\u5217\u6307\u5b9a DEFAULT \u503c\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u5217\u662f\u4e3b\u952e\u6216\u975e\u7a7a\u7ea6\u675f\u7684\uff0c\u5219\u4e0d\u80fd\u4f7f\u7528 DEFAULT\u3002<\/li>\n<li>\u5982\u679c\u5217\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u5141\u8bb8\u9ed8\u8ba4\u503c\uff08\u4f8b\u5982 BLOB \u6216 TEXT\uff09\u3002<\/li>\n<li>\u5982\u679c DEFAULT \u503c\u4e0e\u5217\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u5339\u914d\uff08\u4f8b\u5982\uff0c\u6574\u6570\u5217\u7684\u5b57\u7b26\u4e32\u503c\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>DEFAULT \u503c\u53ef\u4ee5\u5728\u521b\u5efa\u8868\u540e\u4f7f\u7528 ALTER TABLE \u547d\u4ee4\u66f4\u6539\u3002<\/li>\n<li>\u9ed8\u8ba4\u503c\u53ef\u4ee5\u662f\u5e38\u91cf\u3001\u8868\u8fbe\u5f0f\u6216\u5b50\u67e5\u8be2\u7684\u7ed3\u679c\u3002<\/li>\n<li>\u5982\u679c DEFAULT \u503c\u4e3a NULL\uff0c\u5219 NULL \u5c06\u6210\u4e3a\u5217\u7684\u9ed8\u8ba4\u503c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f&nbsp;default\u4ec0\u4e48\u610f\u601d\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 \u4e2d\u7684 default \u5173\u952e\u5b57\u8bbe\u7f6e\u5217\u7684\u9ed8\u8ba4\u503c\uff0c\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3001\u7b80\u5316\u6570\u636e\u63d2\u5165\u548c\u63d0\u4f9b\u6570\u636e\u4e00\u81f4\u6027\u3002\u5b83\u53ef\u4e0e\u5217\u5b9a\u4e49\u4e00\u8d77\u4f7f\u7528\uff0c\u4f46\u4e0d\u53ef\u7528\u4e8e\u4e3b\u952e\u6216\u975e\u7a7a\u7ea6\u675f\u7684\u5217\u3001\u4e0d\u652f\u6301\u9ed8\u8ba4\u503c\u7684\u6570\u636e\u7c7b\u578b\u6216\u4e0d\u5339\u914d\u6570\u636e\u7c7b\u578b\u7684\u9ed8\u8ba4\u503c\u3002\u9ed8\u8ba4\u503c\u53ef\u4ee5\u662f\u5e38\u91cf\u3001\u8868\u8fbe\u5f0f\u6216\u5b50\u67e5\u8be2\u7684\u7ed3\u679c\uff0c\u5e76\u53ef\u4ee5\u5728\u521b\u5efa\u8868\u540e\u66f4\u6539\u3002 MySQL DEFAULT \u542b\u4e49 MySQL \u4e2d\u7684 DEFAULT \u5173\u952e\u5b57\u7528\u4e8e\u8bbe\u7f6e\u4e00\u4e2a\u5217\u5728\u521b\u5efa\u8868\u65f6\u6ca1\u6709\u660e\u786e\u6307\u5b9a\u503c\u7684\u9ed8\u8ba4\u503c\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u65b9\u4fbf\u7684\u65b9\u5f0f\u6765\u786e\u4fdd\u5217\u5728\u6240\u6709\u60c5\u51b5\u4e0b\u90fd\u6709\u4e00\u4e2a\u503c\uff0c\u5373\u4f7f\u672a\u660e\u786e\u63d2\u5165\u3002 \u5982\u4f55\u4f7f\u7528 DEFAULT DEFAULT \u5173\u952e\u5b57\u4e0e\u5217\u5b9a\u4e49\u4e00\u8d77\u4f7f\u7528\uff0c\u5982\u4e0b\u6240\u793a\uff1a CREATE TABLE table_name ( column_name DATATYPE DEFAULT default_value ); \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u5f20\u5305\u542b\u4e00\u4e2a\u5177\u6709\u9ed8\u8ba4\u503c &#8220;Unknown&#8221; \u7684 &#8220;name&#8221; \u5217\u7684\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a CREATE TABLE users ( name VARCHAR(255) DEFAULT &#8220;Unknown&#8221; ); \u767b\u5f55\u540e\u590d\u5236 \u9ed8\u8ba4\u503c\u7684\u4f5c\u7528 \u6307\u5b9a\u5217\u7684 DEFAULT \u503c\u6709\u51e0\u4e2a\u597d\u5904\uff1a \u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\uff1a\u5b83\u9632\u6b62\u5217\u503c\u4e3a\u7a7a\u6216\u672a\u77e5\uff0c\u4ece\u800c\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002 \u7b80\u5316\u6570\u636e\u63d2\u5165\uff1a\u5f53\u521b\u5efa\u65b0\u884c\u65f6\uff0c\u5982\u679c\u672a\u6307\u5b9a\u5217\u503c\uff0c\u5219\u4f7f\u7528\u9ed8\u8ba4\u503c\uff0c\u7b80\u5316\u4e86\u6570\u636e\u63d2\u5165\u8fc7\u7a0b\u3002 \u63d0\u4f9b\u4e00\u81f4\u6027\uff1a\u5b83\u786e\u4fdd\u5217\u5728\u6240\u6709\u884c\u4e2d\u5177\u6709\u76f8\u540c\u7684\u503c\uff0c\u4ece\u800c\u63d0\u4f9b\u6570\u636e\u4e00\u81f4\u6027\u3002 \u7279\u6b8a\u60c5\u51b5 \u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4e0d\u80fd\u4e3a\u5217\u6307\u5b9a DEFAULT \u503c\uff1a \u5982\u679c\u5217\u662f\u4e3b\u952e\u6216\u975e\u7a7a\u7ea6\u675f\u7684\uff0c\u5219\u4e0d\u80fd\u4f7f\u7528 DEFAULT\u3002 \u5982\u679c\u5217\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u5141\u8bb8\u9ed8\u8ba4\u503c\uff08\u4f8b\u5982 BLOB [&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-5769","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5769","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=5769"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5769\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}