{"id":6447,"date":"2024-11-14T13:57:45","date_gmt":"2024-11-14T05:57:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6447\/"},"modified":"2024-11-14T13:57:45","modified_gmt":"2024-11-14T05:57:45","slug":"%e6%80%8e%e4%b9%88mysql%e5%88%9b%e5%bb%ba%e6%95%b0%e6%8d%ae%e5%ba%93%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6447\/","title":{"rendered":"\u600e\u4e48mysql\u521b\u5efa\u6570\u636e\u5e93\u8868"},"content":{"rendered":"<blockquote><p>\n  \u5728 mysql \u4e2d\u521b\u5efa\u6570\u636e\u5e93\u8868\u9700\u8981\u6267\u884c\u516d\u4e2a\u6b65\u9aa4\uff1a1. \u8fde\u63a5\u5230\u670d\u52a1\u5668\uff1b2. \u521b\u5efa\u6570\u636e\u5e93\uff1b3. \u9009\u62e9\u65b0\u6570\u636e\u5e93\uff1b4. \u521b\u5efa\u8868\u5e76\u6307\u5b9a\u5217\u540d\u548c\u6570\u636e\u7c7b\u578b\uff1b5. \u6839\u636e\u9700\u8981\u5b9a\u4e49\u4e3b\u952e\u548c\u7ea6\u675f\uff1b6. \u63d2\u5165\u6570\u636e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080507371068413.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48mysql\u521b\u5efa\u6570\u636e\u5e93\u8868\u63d2\u56fe\" alt=\"\u600e\u4e48mysql\u521b\u5efa\u6570\u636e\u5e93\u8868\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 MySQL \u4e2d\u521b\u5efa\u6570\u636e\u5e93\u8868<\/strong><\/p>\n<p>\u8981\u521b\u5efa MySQL \u6570\u636e\u5e93\u8868\uff0c\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668<\/strong><\/p>\n<pre>mysql -u \u7528\u6237\u540d -p<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u5165\u5bc6\u7801\u5e76\u767b\u5f55\u3002<\/p>\n<p><strong>2. \u521b\u5efa\u6570\u636e\u5e93<\/strong><\/p>\n<pre>CREATE DATABASE \u6570\u636e\u5e93\u540d;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>CREATE DATABASE my_database;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u9009\u62e9\u65b0\u521b\u5efa\u7684\u6570\u636e\u5e93<\/strong><\/p>\n<pre>USE \u6570\u636e\u5e93\u540d;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>USE my_database;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u521b\u5efa\u8868<\/strong><\/p>\n<pre>CREATE TABLE \u8868\u540d (\n  \u5217\u540d \u6570\u636e\u7c7b\u578b NOT NULL,\n  \u5217\u540d \u6570\u636e\u7c7b\u578b NOT NULL,\n  ...\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u5f20\u540d\u4e3a &#8220;users&#8221; \u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b &#8220;id&#8221;\u3001&#8221;name&#8221; \u548c &#8220;email&#8221; \u5217\uff1a<\/p>\n<pre>CREATE TABLE users (\n  id INT NOT NULL AUTO_INCREMENT,\n  name VARCHAR(255) NOT NULL,\n  email VARCHAR(255) NOT NULL\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u5b9a\u4e49\u4e3b\u952e\u548c\u7ea6\u675f<\/strong><\/p>\n<p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u5b9a\u4e49\u4e3b\u952e\u6216\u7ea6\u675f\uff1a<\/p>\n<ul>\n<li> <strong>\u4e3b\u952e\uff1a<\/strong>\u6807\u8bc6\u8868\u4e2d\u552f\u4e00\u6807\u8bc6\u6bcf\u884c\u7684\u5217\u6216\u5217\u7ec4\u5408\u3002<\/li>\n<li> <strong>\u7ea6\u675f\uff1a<\/strong>\u5bf9\u8868\u4e2d\u7684\u6570\u636e\u65bd\u52a0\u9650\u5236\uff0c\u4f8b\u5982\u8981\u6c42\u503c\u4e0d\u4e3a\u7a7a\u6216\u7b26\u5408\u7279\u5b9a\u683c\u5f0f\u3002<\/li>\n<\/ul>\n<p><strong>6. \u63d2\u5165\u6570\u636e<\/strong><\/p>\n<p>\u521b\u5efa\u8868\u540e\uff0c\u53ef\u4ee5\u63d2\u5165\u6570\u636e\uff1a<\/p>\n<pre>INSERT INTO \u8868\u540d (\u5217\u540d1, \u5217\u540d2, ...) VALUES (\u503c1, \u503c2, ...);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u5411 &#8220;users&#8221; \u8868\u4e2d\u63d2\u5165\u4e00\u884c\uff1a<\/p>\n<pre>INSERT INTO users (name, email) VALUES ('John Doe', 'john.doe@example.com');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5b8c\u6210<\/strong><\/p>\n<p>\u5b8c\u6210\u8fd9\u4e9b\u6b65\u9aa4\u540e\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728 MySQL \u6570\u636e\u5e93\u4e2d\u521b\u5efa\u8868\u4e86\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u521b\u5efa\u6570\u636e\u5e93\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 \u4e2d\u521b\u5efa\u6570\u636e\u5e93\u8868\u9700\u8981\u6267\u884c\u516d\u4e2a\u6b65\u9aa4\uff1a1. \u8fde\u63a5\u5230\u670d\u52a1\u5668\uff1b2. \u521b\u5efa\u6570\u636e\u5e93\uff1b3. \u9009\u62e9\u65b0\u6570\u636e\u5e93\uff1b4. \u521b\u5efa\u8868\u5e76\u6307\u5b9a\u5217\u540d\u548c\u6570\u636e\u7c7b\u578b\uff1b5. \u6839\u636e\u9700\u8981\u5b9a\u4e49\u4e3b\u952e\u548c\u7ea6\u675f\uff1b6. \u63d2\u5165\u6570\u636e\u3002 \u5982\u4f55\u5728 MySQL \u4e2d\u521b\u5efa\u6570\u636e\u5e93\u8868 \u8981\u521b\u5efa MySQL \u6570\u636e\u5e93\u8868\uff0c\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668 mysql -u \u7528\u6237\u540d -p \u767b\u5f55\u540e\u590d\u5236 \u8f93\u5165\u5bc6\u7801\u5e76\u767b\u5f55\u3002 2. \u521b\u5efa\u6570\u636e\u5e93 CREATE DATABASE \u6570\u636e\u5e93\u540d; \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff1a CREATE DATABASE my_database; \u767b\u5f55\u540e\u590d\u5236 3. \u9009\u62e9\u65b0\u521b\u5efa\u7684\u6570\u636e\u5e93 USE \u6570\u636e\u5e93\u540d; \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff1a USE my_database; \u767b\u5f55\u540e\u590d\u5236 4. \u521b\u5efa\u8868 CREATE TABLE \u8868\u540d ( \u5217\u540d \u6570\u636e\u7c7b\u578b NOT NULL, [&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-6447","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6447","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=6447"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6447\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}