{"id":6192,"date":"2024-11-14T14:00:01","date_gmt":"2024-11-14T06:00:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6192\/"},"modified":"2024-11-14T14:00:01","modified_gmt":"2024-11-14T06:00:01","slug":"mysql%e9%95%bf%e5%ba%a6%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6192\/","title":{"rendered":"mysql\u957f\u5ea6\u5982\u4f55\u8bbe\u7f6e"},"content":{"rendered":"<blockquote><p>\n  mysql \u5217\u957f\u5ea6\u8bbe\u7f6e\u5bf9\u4e8e\u4f18\u5316\u5b58\u50a8\u7a7a\u95f4\u3001\u63d0\u9ad8\u7d22\u5f15\u6548\u7387\u4ee5\u53ca\u9632\u6b62\u6570\u636e\u9519\u8bef\u81f3\u5173\u91cd\u8981\u3002\u8981\u8bbe\u7f6e\u5217\u957f\u5ea6\uff0c\u8bf7\u4f7f\u7528 create table \u8bed\u6cd5\uff0c\u5176\u4e2d\u5305\u542b\u5217\u7684\u6570\u636e\u7c7b\u578b\u3001\u957f\u5ea6\u548c not null \u9650\u5236\u3002\u9009\u62e9\u9002\u5f53\u7684\u957f\u5ea6\u53d6\u51b3\u4e8e\u6570\u636e\u7c7b\u578b\u3001\u6570\u636e\u5927\u5c0f\u3001\u7d22\u5f15\u4f7f\u7528\u3001\u5b58\u50a8\u7a7a\u95f4\u548c\u5e38\u89c1\u6570\u636e\u7c7b\u578b\u957f\u5ea6\u3002\u901a\u8fc7\u9002\u5f53\u8bbe\u7f6e\u5217\u957f\u5ea6\uff0c\u53ef\u4ee5\u8282\u7701\u5b58\u50a8\u7a7a\u95f4\u3001\u4f18\u5316\u7d22\u5f15\u67e5\u627e\u5e76\u51cf\u5c11\u6570\u636e\u9519\u8bef\u7684\u51fa\u73b0\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/14\/2024061405512873959.jpg\" class=\"aligncenter\" title=\"mysql\u957f\u5ea6\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe\" alt=\"mysql\u957f\u5ea6\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u5217\u957f\u5ea6\u8bbe\u7f6e<\/strong><\/p>\n<p>\u5728 MySQL \u4e2d\u8bbe\u7f6e\u5217\u957f\u5ea6\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4ec5\u5f71\u54cd\u6570\u636e\u5b58\u50a8\u7684\u7a7a\u95f4\u8981\u6c42\uff0c\u8fd8\u5f71\u54cd\u6570\u636e\u64cd\u4f5c\u7684\u6548\u7387\u3002<\/p>\n<p><strong>\u5982\u4f55\u8bbe\u7f6e<\/strong><\/p>\n<p>\u8981\u8bbe\u7f6e\u5217\u957f\u5ea6\uff0c\u8bf7\u5728\u521b\u5efa\u8868\u65f6\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>CREATE TABLE table_name (\n  column_name data_type(length) [NOT NULL]\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>data_type \u662f\u5217\u7684\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<li>length \u662f\u5217\u7684\u957f\u5ea6\uff0c\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\u3002<\/li>\n<li>NOT NULL \u6307\u5b9a\u5217\u662f\u5426\u5141\u8bb8\u7a7a\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u9009\u62e9\u9002\u5f53\u7684\u957f\u5ea6<\/strong><\/p>\n<p>\u9009\u62e9\u9002\u5f53\u7684\u5217\u957f\u5ea6\u53d6\u51b3\u4e8e\u4ee5\u4e0b\u56e0\u7d20\uff1a<\/p>\n<ul>\n<li> <strong>\u6570\u636e\u7c7b\u578b\uff1a<\/strong>\u67d0\u4e9b\u6570\u636e\u7c7b\u578b\uff08\u5982 VARCHAR\uff09\u9700\u8981\u6307\u5b9a\u957f\u5ea6\u3002<\/li>\n<li> <strong>\u6570\u636e\u5927\u5c0f\uff1a<\/strong>\u786e\u5b9a\u5217\u4e2d\u5c06\u5b58\u50a8\u7684\u6570\u636e\u7684\u6700\u5927\u5927\u5c0f\u3002<\/li>\n<li> <strong>\u7d22\u5f15\uff1a<\/strong>\u5982\u679c\u5217\u7528\u4e8e\u7d22\u5f15\uff0c\u5219\u8f83\u77ed\u7684\u957f\u5ea6\u4f1a\u63d0\u9ad8\u7d22\u5f15\u6548\u7387\u3002<\/li>\n<li> <strong>\u5b58\u50a8\u7a7a\u95f4\uff1a<\/strong>\u8f83\u957f\u7684\u957f\u5ea6\u4f1a\u5bfc\u81f4\u66f4\u5927\u7684\u5b58\u50a8\u7a7a\u95f4\u9700\u6c42\u3002<\/li>\n<\/ul>\n<p><strong>\u5e38\u89c1\u6570\u636e\u7c7b\u578b\u957f\u5ea6<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u6570\u636e\u7c7b\u578b\u53ca\u5176\u5efa\u8bae\u957f\u5ea6\uff1a<\/p>\n<ul>\n<li> <strong>CHAR<\/strong> \u548c <strong>VARCHAR<\/strong>\uff1a\u7528\u4e8e\u5b58\u50a8\u56fa\u5b9a\u957f\u5ea6\u6216\u53ef\u53d8\u957f\u5ea6\u7684\u5b57\u7b26\u4e32\u3002\u957f\u5ea6\u5e94\u8db3\u4ee5\u5bb9\u7eb3\u6700\u5927\u9884\u8ba1\u5b57\u7b26\u4e32\u5927\u5c0f\u3002<\/li>\n<li> <strong>INT<\/strong> \u548c <strong>BIGINT<\/strong>\uff1a\u7528\u4e8e\u5b58\u50a8\u6574\u6570\u3002\u957f\u5ea6\u53d6\u51b3\u4e8e\u6570\u636e\u8303\u56f4\u3002<\/li>\n<li> <strong>DECIMAL<\/strong>\uff1a\u7528\u4e8e\u5b58\u50a8\u5341\u8fdb\u5236\u6570\u5b57\u3002\u957f\u5ea6\u5e94\u8003\u8651\u5c0f\u6570\u90e8\u5206\u7684\u7cbe\u5ea6\u548c\u8303\u56f4\u3002<\/li>\n<li> <strong>DATE<\/strong> \u548c <strong>TIME<\/strong>\uff1a\u7528\u4e8e\u5b58\u50a8\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f\u3002\u957f\u5ea6\u56fa\u5b9a\u3002<\/li>\n<li> <strong>BLOB<\/strong> \u548c <strong>TEXT<\/strong>\uff1a\u7528\u4e8e\u5b58\u50a8\u5927\u6587\u672c\u6216\u4e8c\u8fdb\u5236\u6570\u636e\u3002\u957f\u5ea6\u5e94\u5145\u8db3\uff0c\u4f46\u4e0d\u8981\u8fc7\u5ea6\u3002<\/li>\n<\/ul>\n<p><strong>\u5f71\u54cd<\/strong><\/p>\n<p>\u9002\u5f53\u8bbe\u7f6e\u5217\u957f\u5ea6\u53ef\u4ee5\uff1a<\/p>\n<ul>\n<li> <strong>\u4f18\u5316\u5b58\u50a8\u7a7a\u95f4\uff1a<\/strong>\u9632\u6b62\u5b58\u50a8\u4e0d\u5fc5\u8981\u7684\u7a7a\u95f4\u3002<\/li>\n<li> <strong>\u63d0\u9ad8\u7d22\u5f15\u6548\u7387\uff1a<\/strong>\u8f83\u77ed\u7684\u957f\u5ea6\u53ef\u4ee5\u63d0\u9ad8\u7d22\u5f15\u67e5\u627e\u901f\u5ea6\u3002<\/li>\n<li> <strong>\u51cf\u5c11\u9519\u8bef\uff1a<\/strong>\u5728\u63d2\u5165\u6216\u66f4\u65b0\u6570\u636e\u65f6\u5f3a\u5236\u957f\u5ea6\u9650\u5236\u53ef\u4ee5\u9632\u6b62\u6570\u636e\u622a\u65ad\u6216\u6ea2\u51fa\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p><strong>\u6700\u4f73\u5b9e\u8df5<\/strong><\/p>\n<ul>\n<li>\u4ed4\u7ec6\u8003\u8651\u6570\u636e\u9700\u6c42\u5e76\u9009\u62e9\u9002\u5f53\u7684\u957f\u5ea6\u3002<\/li>\n<li>\u907f\u514d\u4f7f\u7528\u8fc7\u957f\u7684\u957f\u5ea6\uff0c\u56e0\u4e3a\u5b83\u4f1a\u6d6a\u8d39\u5b58\u50a8\u7a7a\u95f4\u3002<\/li>\n<li>\u4f7f\u7528 NOT NULL \u9650\u5236\u4ee5\u9632\u6b62\u7a7a\u503c\uff0c\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\u5e76\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3002<\/li>\n<li>\u968f\u7740\u9700\u8981\u8c03\u6574\u5217\u957f\u5ea6\uff0c\u4ee5\u9002\u5e94\u6570\u636e\u6a21\u5f0f\u7684\u53d8\u5316\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u957f\u5ea6\u5982\u4f55\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>mysql \u5217\u957f\u5ea6\u8bbe\u7f6e\u5bf9\u4e8e\u4f18\u5316\u5b58\u50a8\u7a7a\u95f4\u3001\u63d0\u9ad8\u7d22\u5f15\u6548\u7387\u4ee5\u53ca\u9632\u6b62\u6570\u636e\u9519\u8bef\u81f3\u5173\u91cd\u8981\u3002\u8981\u8bbe\u7f6e\u5217\u957f\u5ea6\uff0c\u8bf7\u4f7f\u7528 create table \u8bed\u6cd5\uff0c\u5176\u4e2d\u5305\u542b\u5217\u7684\u6570\u636e\u7c7b\u578b\u3001\u957f\u5ea6\u548c not null \u9650\u5236\u3002\u9009\u62e9\u9002\u5f53\u7684\u957f\u5ea6\u53d6\u51b3\u4e8e\u6570\u636e\u7c7b\u578b\u3001\u6570\u636e\u5927\u5c0f\u3001\u7d22\u5f15\u4f7f\u7528\u3001\u5b58\u50a8\u7a7a\u95f4\u548c\u5e38\u89c1\u6570\u636e\u7c7b\u578b\u957f\u5ea6\u3002\u901a\u8fc7\u9002\u5f53\u8bbe\u7f6e\u5217\u957f\u5ea6\uff0c\u53ef\u4ee5\u8282\u7701\u5b58\u50a8\u7a7a\u95f4\u3001\u4f18\u5316\u7d22\u5f15\u67e5\u627e\u5e76\u51cf\u5c11\u6570\u636e\u9519\u8bef\u7684\u51fa\u73b0\u3002 MySQL \u5217\u957f\u5ea6\u8bbe\u7f6e \u5728 MySQL \u4e2d\u8bbe\u7f6e\u5217\u957f\u5ea6\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4ec5\u5f71\u54cd\u6570\u636e\u5b58\u50a8\u7684\u7a7a\u95f4\u8981\u6c42\uff0c\u8fd8\u5f71\u54cd\u6570\u636e\u64cd\u4f5c\u7684\u6548\u7387\u3002 \u5982\u4f55\u8bbe\u7f6e \u8981\u8bbe\u7f6e\u5217\u957f\u5ea6\uff0c\u8bf7\u5728\u521b\u5efa\u8868\u65f6\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a CREATE TABLE table_name ( column_name data_type(length) [NOT NULL] ); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a data_type \u662f\u5217\u7684\u6570\u636e\u7c7b\u578b\u3002 length \u662f\u5217\u7684\u957f\u5ea6\uff0c\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\u3002 NOT NULL \u6307\u5b9a\u5217\u662f\u5426\u5141\u8bb8\u7a7a\u503c\u3002 \u9009\u62e9\u9002\u5f53\u7684\u957f\u5ea6 \u9009\u62e9\u9002\u5f53\u7684\u5217\u957f\u5ea6\u53d6\u51b3\u4e8e\u4ee5\u4e0b\u56e0\u7d20\uff1a \u6570\u636e\u7c7b\u578b\uff1a\u67d0\u4e9b\u6570\u636e\u7c7b\u578b\uff08\u5982 VARCHAR\uff09\u9700\u8981\u6307\u5b9a\u957f\u5ea6\u3002 \u6570\u636e\u5927\u5c0f\uff1a\u786e\u5b9a\u5217\u4e2d\u5c06\u5b58\u50a8\u7684\u6570\u636e\u7684\u6700\u5927\u5927\u5c0f\u3002 \u7d22\u5f15\uff1a\u5982\u679c\u5217\u7528\u4e8e\u7d22\u5f15\uff0c\u5219\u8f83\u77ed\u7684\u957f\u5ea6\u4f1a\u63d0\u9ad8\u7d22\u5f15\u6548\u7387\u3002 \u5b58\u50a8\u7a7a\u95f4\uff1a\u8f83\u957f\u7684\u957f\u5ea6\u4f1a\u5bfc\u81f4\u66f4\u5927\u7684\u5b58\u50a8\u7a7a\u95f4\u9700\u6c42\u3002 \u5e38\u89c1\u6570\u636e\u7c7b\u578b\u957f\u5ea6 \u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u6570\u636e\u7c7b\u578b\u53ca\u5176\u5efa\u8bae\u957f\u5ea6\uff1a CHAR \u548c VARCHAR\uff1a\u7528\u4e8e\u5b58\u50a8\u56fa\u5b9a\u957f\u5ea6\u6216\u53ef\u53d8\u957f\u5ea6\u7684\u5b57\u7b26\u4e32\u3002\u957f\u5ea6\u5e94\u8db3\u4ee5\u5bb9\u7eb3\u6700\u5927\u9884\u8ba1\u5b57\u7b26\u4e32\u5927\u5c0f\u3002 INT \u548c BIGINT\uff1a\u7528\u4e8e\u5b58\u50a8\u6574\u6570\u3002\u957f\u5ea6\u53d6\u51b3\u4e8e\u6570\u636e\u8303\u56f4\u3002 DECIMAL\uff1a\u7528\u4e8e\u5b58\u50a8\u5341\u8fdb\u5236\u6570\u5b57\u3002\u957f\u5ea6\u5e94\u8003\u8651\u5c0f\u6570\u90e8\u5206\u7684\u7cbe\u5ea6\u548c\u8303\u56f4\u3002 DATE \u548c TIME\uff1a\u7528\u4e8e\u5b58\u50a8\u65e5\u671f\u548c\u65f6\u95f4\u4fe1\u606f\u3002\u957f\u5ea6\u56fa\u5b9a\u3002 BLOB \u548c TEXT\uff1a\u7528\u4e8e\u5b58\u50a8\u5927\u6587\u672c\u6216\u4e8c\u8fdb\u5236\u6570\u636e\u3002\u957f\u5ea6\u5e94\u5145\u8db3\uff0c\u4f46\u4e0d\u8981\u8fc7\u5ea6\u3002 [&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-6192","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6192","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=6192"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6192\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}