{"id":5433,"date":"2024-11-14T10:38:03","date_gmt":"2024-11-14T02:38:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5433\/"},"modified":"2024-11-14T10:38:03","modified_gmt":"2024-11-14T02:38:03","slug":"mysql%e6%80%8e%e4%b9%88%e5%81%9a%e8%a1%a8%e6%a0%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5433\/","title":{"rendered":"mysql\u600e\u4e48\u505a\u8868\u683c"},"content":{"rendered":"<blockquote><p>\n  \u5728 mysql \u4e2d\u521b\u5efa\u8868\u683c\u7684\u6b65\u9aa4\uff1a\u4f7f\u7528 create table \u8bed\u53e5\u521b\u5efa\u8868\u683c\uff0c\u6307\u5b9a\u8868\u683c\u540d\u79f0\u548c\u5217\u5c5e\u6027\u3002\u5217\u5c5e\u6027\u5305\u62ec\u6570\u636e\u7c7b\u578b\u3001\u7ea6\u675f\u3001\u9ed8\u8ba4\u503c\u548c\u4e3b\u952e\u3002\u6267\u884c\u67e5\u8be2\u4ee5\u521b\u5efa\u8868\u683c\uff0c\u4f8b\u5982\uff1acreate table customers (id int not null auto_increment, name varchar(255) not null, email varchar(255) unique, phone varchar(15) not null);\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052812512773319.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u505a\u8868\u683c\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u505a\u8868\u683c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 MySQL \u4e2d\u521b\u5efa\u8868\u683c<\/strong><\/p>\n<p>\u5728 MySQL \u6570\u636e\u5e93\u4e2d\u521b\u5efa\u8868\u683c\u662f\u5b58\u50a8\u548c\u7ec4\u7ec7\u6570\u636e\u7684\u57fa\u672c\u6b65\u9aa4\u3002\u4ee5\u4e0b\u662f\u521b\u5efa\u8868\u683c\u7684\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li><strong>\u542f\u52a8 MySQL \u5ba2\u6237\u7aef<\/strong><\/li>\n<\/ol>\n<p>\u6253\u5f00 MySQL \u547d\u4ee4\u884c\u754c\u9762\u6216\u4f7f\u7528 MySQL GUI \u5de5\u5177\u3002<\/p>\n<ol>\n<li><strong>\u8fde\u63a5\u5230\u6570\u636e\u5e93<\/strong><\/li>\n<\/ol>\n<p>\u4f7f\u7528 USE \u547d\u4ee4\u8fde\u63a5\u5230\u8981\u521b\u5efa\u8868\u683c\u7684\u6570\u636e\u5e93\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>USE my_database;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u521b\u5efa\u8868\u683c<\/strong><\/li>\n<\/ol>\n<p>\u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u521b\u5efa\u8868\u683c\u3002\u8be5\u8bed\u53e5\u7684\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>CREATE TABLE table_name (\n  column1_name data_type [column_constraints],\n  column2_name data_type [column_constraints],\n  ...\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>table_name \u662f\u8981\u521b\u5efa\u7684\u8868\u683c\u7684\u540d\u79f0\u3002<\/li>\n<li>column1_name \u662f\u7b2c\u4e00\u4e2a\u5217\u7684\u540d\u79f0\u3002<\/li>\n<li>data_type \u662f\u5217\u7684\u6570\u636e\u7c7b\u578b\uff08\u4f8b\u5982\uff0cINT\u3001VARCHAR\u3001DATE \u7b49\uff09\u3002<\/li>\n<li>column_constraints \u662f\u5bf9\u5217\u5e94\u7528\u7684\u7ea6\u675f\uff08\u4f8b\u5982\uff0cNOT NULL\u3001UNIQUE \u7b49\uff09\u3002<\/li>\n<\/ul>\n<ol>\n<li><strong>\u6307\u5b9a\u5217\u7684\u5c5e\u6027<\/strong><\/li>\n<\/ol>\n<p>\u6bcf\u4e2a\u5217\u90fd\u6709\u81ea\u5df1\u7684\u5c5e\u6027\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u6570\u636e\u7c7b\u578b\uff1a\u6307\u5b9a\u5217\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<li>\u7ea6\u675f\uff1a\u9650\u5236\u5b58\u50a8\u5728\u5217\u4e2d\u7684\u503c\u3002<\/li>\n<li>\u9ed8\u8ba4\u503c\uff1a\u4e3a\u65b0\u63d2\u5165\u7684\u884c\u63d0\u4f9b\u9ed8\u8ba4\u503c\u3002<\/li>\n<li>\u4e3b\u952e\uff1a\u6807\u8bc6\u8868\u683c\u4e2d\u6bcf\u884c\u7684\u552f\u4e00\u503c\u3002<\/li>\n<li>\u5916\u952e\uff1a\u5c06\u4e00\u4e2a\u8868\u4e2d\u7684\u5217\u94fe\u63a5\u5230\u53e6\u4e00\u4e2a\u8868\u4e2d\u7684\u5217\u3002<\/li>\n<\/ul>\n<ol>\n<li><strong>\u6267\u884c\u67e5\u8be2<\/strong><\/li>\n<\/ol>\n<p>\u8f93\u5165 CREATE TABLE \u8bed\u53e5\u5e76\u6309\u56de\u8f66\u952e\u6267\u884c\u67e5\u8be2\u3002<\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a customers \u7684\u8868\u683c\uff0c\u5176\u4e2d\u5305\u542b id\u3001name\u3001email \u548c phone \u5217\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>CREATE TABLE customers (\n  id INT NOT NULL AUTO_INCREMENT,\n  name VARCHAR(255) NOT NULL,\n  email VARCHAR(255) UNIQUE,\n  phone VARCHAR(15) NOT NULL\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u67e5\u8be2\u521b\u5efa\u4e86\u4e00\u4e2a\u5e26\u6709 4 \u4e2a\u5217\u7684\u8868\u683c\uff1a<\/p>\n<ul>\n<li>id \u5217\u662f\u4e00\u4e2a\u6574\u6570\u7c7b\u578b\uff0c\u5b83\u81ea\u52a8\u9012\u589e\uff0c\u56e0\u4e3a\u6307\u5b9a\u4e86 AUTO_INCREMENT\u3002<\/li>\n<li>name \u5217\u662f\u4e00\u4e2a\u6587\u672c\u7c7b\u578b\uff0c\u5b83\u4e0d\u80fd\u4e3a NULL\u3002<\/li>\n<li>email \u5217\u662f\u4e00\u4e2a\u6587\u672c\u7c7b\u578b\uff0c\u5b83\u5fc5\u987b\u662f\u552f\u4e00\u7684\u3002<\/li>\n<li>phone \u5217\u662f\u4e00\u4e2a\u6587\u672c\u7c7b\u578b\uff0c\u5b83\u4e0d\u80fd\u4e3a NULL\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u505a\u8868\u683c\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>\u5728 mysql \u4e2d\u521b\u5efa\u8868\u683c\u7684\u6b65\u9aa4\uff1a\u4f7f\u7528 create table \u8bed\u53e5\u521b\u5efa\u8868\u683c\uff0c\u6307\u5b9a\u8868\u683c\u540d\u79f0\u548c\u5217\u5c5e\u6027\u3002\u5217\u5c5e\u6027\u5305\u62ec\u6570\u636e\u7c7b\u578b\u3001\u7ea6\u675f\u3001\u9ed8\u8ba4\u503c\u548c\u4e3b\u952e\u3002\u6267\u884c\u67e5\u8be2\u4ee5\u521b\u5efa\u8868\u683c\uff0c\u4f8b\u5982\uff1acreate table customers (id int not null auto_increment, name varchar(255) not null, email varchar(255) unique, phone varchar(15) not null); \u5728 MySQL \u4e2d\u521b\u5efa\u8868\u683c \u5728 MySQL \u6570\u636e\u5e93\u4e2d\u521b\u5efa\u8868\u683c\u662f\u5b58\u50a8\u548c\u7ec4\u7ec7\u6570\u636e\u7684\u57fa\u672c\u6b65\u9aa4\u3002\u4ee5\u4e0b\u662f\u521b\u5efa\u8868\u683c\u7684\u6b65\u9aa4\uff1a \u542f\u52a8 MySQL \u5ba2\u6237\u7aef \u6253\u5f00 MySQL \u547d\u4ee4\u884c\u754c\u9762\u6216\u4f7f\u7528 MySQL GUI \u5de5\u5177\u3002 \u8fde\u63a5\u5230\u6570\u636e\u5e93 \u4f7f\u7528 USE \u547d\u4ee4\u8fde\u63a5\u5230\u8981\u521b\u5efa\u8868\u683c\u7684\u6570\u636e\u5e93\u3002\u4f8b\u5982\uff1a USE my_database; \u767b\u5f55\u540e\u590d\u5236 \u521b\u5efa\u8868\u683c \u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u521b\u5efa\u8868\u683c\u3002\u8be5\u8bed\u53e5\u7684\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a CREATE TABLE table_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-5433","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5433","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=5433"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5433\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}