{"id":6362,"date":"2024-11-14T14:28:11","date_gmt":"2024-11-14T06:28:11","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6362\/"},"modified":"2024-11-14T14:28:11","modified_gmt":"2024-11-14T06:28:11","slug":"mysql%e6%80%8e%e4%b9%88%e5%88%9b%e5%bb%ba%e4%b8%80%e4%b8%aa%e8%a1%a8%e6%a0%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6362\/","title":{"rendered":"mysql\u600e\u4e48\u521b\u5efa\u4e00\u4e2a\u8868\u683c"},"content":{"rendered":"<blockquote><p>\n  \u5728 mysql \u4e2d\u521b\u5efa\u8868\u683c\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u8fde\u63a5\u5230\u6570\u636e\u5e93\u670d\u52a1\u5668\u3002\u9009\u62e9\u8981\u521b\u5efa\u8868\u683c\u7684\u6570\u636e\u5e93\u3002\u4f7f\u7528 create table \u8bed\u53e5\u521b\u5efa\u65b0\u8868\u683c\uff0c\u6307\u5b9a\u8868\u683c\u540d\u3001\u5217\u540d\u3001\u6570\u636e\u7c7b\u578b\u548c\u4e3b\u952e\u3002\u4f7f\u7528 show tables \u547d\u4ee4\u9a8c\u8bc1\u8868\u683c\u662f\u5426\u6210\u529f\u521b\u5efa\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/01\/2024080102580523151.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u521b\u5efa\u4e00\u4e2a\u8868\u683c\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u521b\u5efa\u4e00\u4e2a\u8868\u683c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u521b\u5efa MySQL \u8868\u683c<\/strong><\/p>\n<p>\u5728 MySQL \u4e2d\u521b\u5efa\u8868\u683c\u662f\u4e00\u4e2a\u57fa\u672c\u64cd\u4f5c\uff0c\u53ef\u4ee5\u5b58\u50a8\u548c\u7ba1\u7406\u6570\u636e\u3002\u4ee5\u4e0b\u6b65\u9aa4\u6307\u5bfc\u60a8\u521b\u5efa\u65b0\u7684 MySQL \u8868\u683c\uff1a<\/p>\n<p><strong>1. \u6253\u5f00 MySQL \u547d\u4ee4\u884c\u754c\u9762<\/strong><\/p>\n<p>\u6253\u5f00 MySQL \u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u7a97\u53e3\uff0c\u5e76\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fde\u63a5\u5230\u6570\u636e\u5e93\u670d\u52a1\u5668\uff1a<\/p>\n<pre>mysql -u username -p password<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>username \u662f\u60a8\u7684 MySQL \u7528\u6237\u540d<\/li>\n<li>password \u662f\u60a8\u7684 MySQL \u5bc6\u7801<\/li>\n<\/ul>\n<p><strong>2. \u9009\u62e9\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u5728 MySQL \u547d\u4ee4\u884c\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9009\u62e9\u8981\u521b\u5efa\u8868\u683c\u7684\u6570\u636e\u5e93\uff1a<\/p>\n<pre>USE database_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d database_name \u662f\u60a8\u8981\u521b\u5efa\u8868\u683c\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002<\/p>\n<p><strong>3. \u521b\u5efa\u8868\u683c<\/strong><\/p>\n<p>\u4f7f\u7528 CREATE TABLE \u8bed\u53e5\u521b\u5efa\u65b0\u8868\u683c\u3002\u8be5\u8bed\u53e5\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>CREATE TABLE table_name (\n  column_name data_type NOT NULL,\n  ...\n  PRIMARY KEY (column_name)\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>table_name \u662f\u65b0\u8868\u683c\u7684\u540d\u79f0<\/li>\n<li>column_name \u662f\u8868\u683c\u5217\u7684\u540d\u79f0<\/li>\n<li>data_type \u662f\u5217\u7684\u6570\u636e\u7c7b\u578b<\/li>\n<li>NOT NULL \u7ea6\u675f\u8868\u793a\u8be5\u5217\u4e0d\u5141\u8bb8\u4e3a NULL \u503c<\/li>\n<li>PRIMARY KEY \u7ea6\u675f\u6307\u5b9a\u8868\u7684\u4e3b\u952e\uff0c\u8be5\u952e\u552f\u4e00\u6807\u8bc6\u8868\u4e2d\u7684\u6bcf\u884c<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u521b\u5efa\u540d\u4e3a customers \u7684\u8868\u683c\uff0c\u5176\u4e2d\u5305\u542b\u5ba2\u6237\u4fe1\u606f\uff1a<\/p>\n<pre>CREATE TABLE customers (\n  id INT NOT NULL AUTO_INCREMENT,\n  name VARCHAR(255) NOT NULL,\n  email VARCHAR(255) NOT NULL,\n  PRIMARY KEY (id)\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a customers \u7684\u65b0\u8868\u683c\uff0c\u5176\u4e2d\u6709\u4e09\u4e2a\u5217\uff1a<\/p>\n<ul>\n<li>id\uff1a\u4e00\u4e2a\u81ea\u52a8\u9012\u589e\u7684\u6574\u578b\u4e3b\u952e<\/li>\n<li>name\uff1a\u4e00\u4e2a\u6700\u591a\u5305\u542b 255 \u4e2a\u5b57\u7b26\u7684\u6587\u672c\u5217<\/li>\n<li>email\uff1a\u4e00\u4e2a\u6700\u591a\u5305\u542b 255 \u4e2a\u5b57\u7b26\u7684\u6587\u672c\u5217<\/li>\n<\/ul>\n<p><strong>4. \u9a8c\u8bc1\u8868\u683c\u521b\u5efa<\/strong><\/p>\n<p>\u521b\u5efa\u8868\u683c\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 SHOW TABLES \u547d\u4ee4\u9a8c\u8bc1\u5b83\u662f\u5426\u6210\u529f\u521b\u5efa\uff1a<\/p>\n<pre>SHOW TABLES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u679c\u8868\u683c\u5df2\u6210\u529f\u521b\u5efa\uff0c\u60a8\u5c06\u770b\u5230\u5b83\u5217\u5728\u547d\u4ee4\u8f93\u51fa\u4e2d\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u521b\u5efa\u4e00\u4e2a\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\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u8fde\u63a5\u5230\u6570\u636e\u5e93\u670d\u52a1\u5668\u3002\u9009\u62e9\u8981\u521b\u5efa\u8868\u683c\u7684\u6570\u636e\u5e93\u3002\u4f7f\u7528 create table \u8bed\u53e5\u521b\u5efa\u65b0\u8868\u683c\uff0c\u6307\u5b9a\u8868\u683c\u540d\u3001\u5217\u540d\u3001\u6570\u636e\u7c7b\u578b\u548c\u4e3b\u952e\u3002\u4f7f\u7528 show tables \u547d\u4ee4\u9a8c\u8bc1\u8868\u683c\u662f\u5426\u6210\u529f\u521b\u5efa\u3002 \u5982\u4f55\u521b\u5efa MySQL \u8868\u683c \u5728 MySQL \u4e2d\u521b\u5efa\u8868\u683c\u662f\u4e00\u4e2a\u57fa\u672c\u64cd\u4f5c\uff0c\u53ef\u4ee5\u5b58\u50a8\u548c\u7ba1\u7406\u6570\u636e\u3002\u4ee5\u4e0b\u6b65\u9aa4\u6307\u5bfc\u60a8\u521b\u5efa\u65b0\u7684 MySQL \u8868\u683c\uff1a 1. \u6253\u5f00 MySQL \u547d\u4ee4\u884c\u754c\u9762 \u6253\u5f00 MySQL \u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u7a97\u53e3\uff0c\u5e76\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fde\u63a5\u5230\u6570\u636e\u5e93\u670d\u52a1\u5668\uff1a mysql -u username -p password \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a username \u662f\u60a8\u7684 MySQL \u7528\u6237\u540d password \u662f\u60a8\u7684 MySQL \u5bc6\u7801 2. \u9009\u62e9\u6570\u636e\u5e93 \u5728 MySQL \u547d\u4ee4\u884c\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9009\u62e9\u8981\u521b\u5efa\u8868\u683c\u7684\u6570\u636e\u5e93\uff1a USE database_name; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d database_name \u662f\u60a8\u8981\u521b\u5efa\u8868\u683c\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002 3. \u521b\u5efa\u8868\u683c \u4f7f\u7528 CREATE TABLE [&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-6362","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6362","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=6362"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6362\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}