{"id":6621,"date":"2024-11-14T13:38:25","date_gmt":"2024-11-14T05:38:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6621\/"},"modified":"2024-11-14T13:38:25","modified_gmt":"2024-11-14T05:38:25","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%80%8e%e4%b9%88%e7%94%a8-mysql%e6%80%8e%e4%b9%88%e5%bb%ba%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6621\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u600e\u4e48\u7528 mysql\u600e\u4e48\u5efa\u6570\u636e\u5e93"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u4f7f\u7528 mysql \u6570\u636e\u5e93\uff1f\u521b\u5efa\u6570\u636e\u5e93\uff08\u4f7f\u7528 create database \u547d\u4ee4\uff09\u3002\u521b\u5efa\u8868\uff08\u4f7f\u7528 create table \u547d\u4ee4\uff0c\u6307\u5b9a\u5217\u540d\u548c\u6570\u636e\u7c7b\u578b\uff09\u3002\u63d2\u5165\u6570\u636e\uff08\u4f7f\u7528 insert into \u8bed\u53e5\uff09\u3002\u67e5\u8be2\u6570\u636e\uff08\u4f7f\u7528 select \u8bed\u53e5\uff0c\u53ef\u9009 where \u6761\u4ef6\uff09\u3002\u66f4\u65b0\u6570\u636e\uff08\u4f7f\u7528 update \u8bed\u53e5\uff0c\u6307\u5b9a set \u5b50\u53e5\u548c where \u6761\u4ef6\uff09\u3002\u5220\u9664\u6570\u636e\uff08\u4f7f\u7528 delete \u8bed\u53e5\uff0c\u6307\u5b9a where \u6761\u4ef6\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/13\/2024081313522590169.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u7528 mysql\u600e\u4e48\u5efa\u6570\u636e\u5e93\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u7528 mysql\u600e\u4e48\u5efa\u6570\u636e\u5e93\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 MySQL \u6570\u636e\u5e93<\/strong><\/p>\n<p><strong>1. \u521b\u5efa MySQL \u6570\u636e\u5e93<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 MySQL \u547d\u4ee4\u884c\u5de5\u5177\uff0c\u8f93\u5165  -u root -p \u767b\u5f55 MySQL\u3002<\/li>\n<li>\u952e\u5165\u5bc6\u7801\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u6570\u636e\u5e93\uff1a<\/li>\n<\/ul>\n<pre>CREATE DATABASE database_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d database_name \u662f\u60a8\u8981\u521b\u5efa\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002<\/p>\n<p><strong>2. \u521b\u5efa MySQL \u8868<\/strong><\/p>\n<ul>\n<li>\u5728\u8981\u521b\u5efa\u8868\u6240\u5728\u7684\u6570\u636e\u5e93\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ul>\n<pre>CREATE TABLE table_name (\n  column_name data_type [NOT NULL] [DEFAULT default_value]\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<pre>* `table_name` \u662f\u8981\u521b\u5efa\u7684\u8868\u7684\u540d\u79f0\u3002\n* `column_name` \u662f\u8868\u7684\u5217\u540d\u79f0\u3002\n* `data_type` \u662f\u5217\u7684\u6570\u636e\u7c7b\u578b\uff08\u4f8b\u5982 INT\u3001VARCHAR\u3001DATE\uff09\u3002\n* `NOT NULL` \u7ea6\u675f\u786e\u4fdd\u5217\u4e0d\u80fd\u5305\u542b NULL \u503c\u3002\n* `DEFAULT default_value` \u7ea6\u675f\u8bbe\u7f6e\u5217\u7684\u9ed8\u8ba4\u503c\u3002\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u63d2\u5165\u6570\u636e<\/strong><\/p>\n<ul>\n<li>\u60a8\u53ef\u4ee5\u4f7f\u7528 INSERT INTO \u8bed\u53e5\u5411\u8868\u4e2d\u63d2\u5165\u6570\u636e\uff1a<\/li>\n<\/ul>\n<pre>INSERT INTO table_name (column1, column2, ...)\nVALUES (value1, value2, ...);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528 LOAD DATA INFILE \u547d\u4ee4\u4ece CSV \u6587\u4ef6\u5bfc\u5165\u5927\u91cf\u6570\u636e\u3002<\/li>\n<\/ul>\n<p><strong>4. \u67e5\u8be2\u6570\u636e<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 SELECT \u8bed\u53e5\u4ece\u8868\u4e2d\u67e5\u8be2\u6570\u636e\uff1a<\/li>\n<\/ul>\n<pre>SELECT column1, column2, ...\nFROM table_name\nWHERE condition;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>WHERE \u5b50\u53e5\u5141\u8bb8\u60a8\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u8fc7\u6ee4\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<p><strong>5. \u66f4\u65b0\u6570\u636e<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 UPDATE \u8bed\u53e5\u66f4\u65b0\u8868\u4e2d\u7684\u6570\u636e\uff1a<\/li>\n<\/ul>\n<pre>UPDATE table_name\nSET column1 = value1, column2 = value2, ...\nWHERE condition;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>SET \u5b50\u53e5\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u5217\u548c\u503c\u3002<\/li>\n<li>WHERE \u5b50\u53e5\u6307\u5b9a\u8981\u66f4\u65b0\u54ea\u4e9b\u884c\u3002<\/li>\n<\/ul>\n<p><strong>6. \u5220\u9664\u6570\u636e<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 DELETE \u8bed\u53e5\u4ece\u8868\u4e2d\u5220\u9664\u6570\u636e\uff1a<\/li>\n<\/ul>\n<pre>DELETE FROM table_name\nWHERE condition;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>WHERE \u5b50\u53e5\u6307\u5b9a\u8981\u5220\u9664\u54ea\u4e9b\u884c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u600e\u4e48\u7528 mysql\u600e\u4e48\u5efa\u6570\u636e\u5e93\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>\u5982\u4f55\u4f7f\u7528 mysql \u6570\u636e\u5e93\uff1f\u521b\u5efa\u6570\u636e\u5e93\uff08\u4f7f\u7528 create database \u547d\u4ee4\uff09\u3002\u521b\u5efa\u8868\uff08\u4f7f\u7528 create table \u547d\u4ee4\uff0c\u6307\u5b9a\u5217\u540d\u548c\u6570\u636e\u7c7b\u578b\uff09\u3002\u63d2\u5165\u6570\u636e\uff08\u4f7f\u7528 insert into \u8bed\u53e5\uff09\u3002\u67e5\u8be2\u6570\u636e\uff08\u4f7f\u7528 select \u8bed\u53e5\uff0c\u53ef\u9009 where \u6761\u4ef6\uff09\u3002\u66f4\u65b0\u6570\u636e\uff08\u4f7f\u7528 update \u8bed\u53e5\uff0c\u6307\u5b9a set \u5b50\u53e5\u548c where \u6761\u4ef6\uff09\u3002\u5220\u9664\u6570\u636e\uff08\u4f7f\u7528 delete \u8bed\u53e5\uff0c\u6307\u5b9a where \u6761\u4ef6\uff09\u3002 \u5982\u4f55\u4f7f\u7528 MySQL \u6570\u636e\u5e93 1. \u521b\u5efa MySQL \u6570\u636e\u5e93 \u4f7f\u7528 MySQL \u547d\u4ee4\u884c\u5de5\u5177\uff0c\u8f93\u5165 -u root -p \u767b\u5f55 MySQL\u3002 \u952e\u5165\u5bc6\u7801\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u6570\u636e\u5e93\uff1a CREATE DATABASE database_name; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d database_name \u662f\u60a8\u8981\u521b\u5efa\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002 2. \u521b\u5efa MySQL \u8868 \u5728\u8981\u521b\u5efa\u8868\u6240\u5728\u7684\u6570\u636e\u5e93\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a CREATE [&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-6621","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6621","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=6621"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6621\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}