{"id":5236,"date":"2024-11-14T08:13:29","date_gmt":"2024-11-14T00:13:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5236\/"},"modified":"2024-11-14T08:13:29","modified_gmt":"2024-11-14T00:13:29","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%80%8e%e4%b9%88%e5%bb%ba%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5236\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u600e\u4e48\u5efa\u8868"},"content":{"rendered":"<blockquote><p>\n  \u5728 mysql \u6570\u636e\u5e93\u4e2d\u521b\u5efa\u8868\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u767b\u5f55 mysql \u5ba2\u6237\u7aef\u5e76\u9009\u62e9\u6570\u636e\u5e93\u3002\u4f7f\u7528 create table \u8bed\u53e5\u521b\u5efa\u8868\uff0c\u6307\u5b9a\u8868\u540d\u3001\u5217\u540d\u548c\u6570\u636e\u7c7b\u578b\u3002\u6dfb\u52a0\u4e3b\u952e\u3001\u5916\u952e\u3001\u975e\u7a7a\u7b49\u7ea6\u675f\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002\u6267\u884c create table \u8bed\u53e5\uff0c\u7136\u540e\u8868\u5c31\u521b\u5efa\u597d\u4e86\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/26\/2024052617125348314.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5efa\u8868\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5efa\u8868\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u6570\u636e\u5e93\u5efa\u8868\u6559\u7a0b<\/strong><\/p>\n<p>\u5728 MySQL \u6570\u636e\u5e93\u4e2d\uff0c\u521b\u5efa\u8868\u662f\u5b58\u50a8\u548c\u7ec4\u7ec7\u6570\u636e\u7684\u5173\u952e\u4e00\u6b65\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5206\u6b65\u6307\u5357\uff0c\u4ecb\u7ecd\u5982\u4f55\u521b\u5efa\u8868\uff1a<\/p>\n<p><strong>1. \u6253\u5f00 MySQL \u5ba2\u6237\u7aef<\/strong><\/p>\n<p>\u767b\u5f55\u5230 MySQL \u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u6216 GUI \u5ba2\u6237\u7aef\u3002<\/p>\n<p><strong>2. \u9009\u62e9\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u4f7f\u7528 USE \u8bed\u53e5\u9009\u62e9\u8981\u521b\u5efa\u8868\u7684\u6570\u636e\u5e93\uff1a<\/p>\n<pre>USE my_database;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u521b\u5efa\u8868<\/strong><\/p>\n<p>\u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u521b\u5efa\u8868\u3002\u8be5\u8bed\u53e5\u5305\u542b\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>CREATE TABLE table_name (\n  column_name1 data_type [column_constraints],\n  column_name2 data_type [column_constraints],\n  ...\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>table_name\uff1a<\/strong>\u8868\u7684\u540d\u79f0\u3002<\/li>\n<li> <strong>column_name\uff1a<\/strong>\u8868\u7684\u5217\u7684\u540d\u79f0\u3002<\/li>\n<li> <strong>data_type\uff1a<\/strong>\u5217\u7684\u6570\u636e\u7c7b\u578b\uff0c\u4f8b\u5982 INT\u3001VARCHAR \u6216 DATE\u3002<\/li>\n<li> <strong>column_constraints\uff1a<\/strong>\u53ef\u9009\u7684\u7ea6\u675f\uff0c\u4f8b\u5982\u4e3b\u952e\u3001\u5916\u952e\u6216\u975e\u7a7a\u7ea6\u675f\u3002<\/li>\n<\/ul>\n<p><strong>4. \u6307\u5b9a\u5217<\/strong><\/p>\n<p>\u5728 CREATE TABLE \u8bed\u53e5\u4e2d\uff0c\u6307\u5b9a\u8868\u7684\u5217\u53ca\u5176\u6570\u636e\u7c7b\u578b\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li> <strong>\u6570\u5b57\uff1a<\/strong> INT\u3001BIGINT\u3001DECIMAL<\/li>\n<li> <strong>\u5b57\u7b26\uff1a<\/strong> VARCHAR\u3001CHAR\u3001TEXT<\/li>\n<li> <strong>\u65e5\u671f\u548c\u65f6\u95f4\uff1a<\/strong> DATE\u3001TIME\u3001DATETIME<\/li>\n<\/ul>\n<p><strong>5. \u6dfb\u52a0\u7ea6\u675f<\/strong><\/p>\n<p>\u7ea6\u675f\u53ef\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u4e00\u81f4\u6027\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7ea6\u675f\uff1a<\/p>\n<ul>\n<li> <strong>PRIMARY KEY\uff1a<\/strong>\u6307\u5b9a\u8868\u7684\u552f\u4e00\u6807\u8bc6\u7b26\u5217\u3002<\/li>\n<li> <strong>FOREIGN KEY\uff1a<\/strong>\u6307\u5b9a\u5217\u4e0e\u53e6\u4e00\u4e2a\u8868\u4e2d\u7684\u5217\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/li>\n<li> <strong>NOT NULL\uff1a<\/strong>\u786e\u4fdd\u5217\u4e0d\u5305\u542b\u7a7a\u503c\u3002<\/li>\n<li> <strong>UNIQUE\uff1a<\/strong>\u786e\u4fdd\u5217\u4e2d\u7684\u6240\u6709\u503c\u90fd\u662f\u552f\u4e00\u7684\u3002<\/li>\n<\/ul>\n<p><strong>6. \u6267\u884c\u8bed\u53e5<\/strong><\/p>\n<p>\u6267\u884c CREATE TABLE \u8bed\u53e5\uff1a<\/p>\n<pre>CREATE TABLE employees (\n  id INT PRIMARY KEY AUTO_INCREMENT,\n  name VARCHAR(255) NOT NULL,\n  email VARCHAR(255) UNIQUE,\n  phone_number VARCHAR(15)\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a customers \u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b id\u3001name\u3001address \u548c phone_number \u5217\uff1a<\/p>\n<pre>CREATE TABLE customers (\n  id INT PRIMARY KEY AUTO_INCREMENT,\n  name VARCHAR(255) NOT NULL,\n  address VARCHAR(500),\n  phone_number VARCHAR(20)\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u600e\u4e48\u5efa\u8868\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 \u6570\u636e\u5e93\u4e2d\u521b\u5efa\u8868\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u767b\u5f55 mysql \u5ba2\u6237\u7aef\u5e76\u9009\u62e9\u6570\u636e\u5e93\u3002\u4f7f\u7528 create table \u8bed\u53e5\u521b\u5efa\u8868\uff0c\u6307\u5b9a\u8868\u540d\u3001\u5217\u540d\u548c\u6570\u636e\u7c7b\u578b\u3002\u6dfb\u52a0\u4e3b\u952e\u3001\u5916\u952e\u3001\u975e\u7a7a\u7b49\u7ea6\u675f\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002\u6267\u884c create table \u8bed\u53e5\uff0c\u7136\u540e\u8868\u5c31\u521b\u5efa\u597d\u4e86\u3002 MySQL \u6570\u636e\u5e93\u5efa\u8868\u6559\u7a0b \u5728 MySQL \u6570\u636e\u5e93\u4e2d\uff0c\u521b\u5efa\u8868\u662f\u5b58\u50a8\u548c\u7ec4\u7ec7\u6570\u636e\u7684\u5173\u952e\u4e00\u6b65\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5206\u6b65\u6307\u5357\uff0c\u4ecb\u7ecd\u5982\u4f55\u521b\u5efa\u8868\uff1a 1. \u6253\u5f00 MySQL \u5ba2\u6237\u7aef \u767b\u5f55\u5230 MySQL \u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u6216 GUI \u5ba2\u6237\u7aef\u3002 2. \u9009\u62e9\u6570\u636e\u5e93 \u4f7f\u7528 USE \u8bed\u53e5\u9009\u62e9\u8981\u521b\u5efa\u8868\u7684\u6570\u636e\u5e93\uff1a USE my_database; \u767b\u5f55\u540e\u590d\u5236 3. \u521b\u5efa\u8868 \u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u521b\u5efa\u8868\u3002\u8be5\u8bed\u53e5\u5305\u542b\u4ee5\u4e0b\u8bed\u6cd5\uff1a CREATE TABLE table_name ( column_name1 data_type [column_constraints], column_name2 data_type [column_constraints], &#8230; ); \u767b\u5f55\u540e\u590d\u5236 table_name\uff1a\u8868\u7684\u540d\u79f0\u3002 column_name\uff1a\u8868\u7684\u5217\u7684\u540d\u79f0\u3002 data_type\uff1a\u5217\u7684\u6570\u636e\u7c7b\u578b\uff0c\u4f8b\u5982 [&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-5236","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5236","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=5236"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5236\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}