{"id":6156,"date":"2024-11-14T11:50:17","date_gmt":"2024-11-14T03:50:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6156\/"},"modified":"2024-11-14T11:50:17","modified_gmt":"2024-11-14T03:50:17","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a6%82%e4%bd%95%e5%af%bc%e5%85%a5excel","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6156\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u5982\u4f55\u5bfc\u5165excel"},"content":{"rendered":"<blockquote><p>\n  \u5c06 excel \u6570\u636e\u5bfc\u5165 mysql \u6570\u636e\u5e93\u53ef\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a1. \u8fde\u63a5\u6570\u636e\u5e93\uff1b2. \u521b\u5efa\u6570\u636e\u5e93\uff08\u53ef\u9009\uff09\uff1b3. \u521b\u5efa\u8868\uff1b4. \u5bfc\u51fa excel \u6570\u636e\u4e3a csv \u6587\u4ef6\uff1b5. \u4f7f\u7528 load data infile \u52a0\u8f7d\u6570\u636e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/14\/2024061403152795649.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u5982\u4f55\u5bfc\u5165excel\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u5982\u4f55\u5bfc\u5165excel\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 Excel \u6570\u636e\u5bfc\u5165 MySQL \u6570\u636e\u5e93\uff1f<\/strong><\/p>\n<p>\u5c06 Excel \u6570\u636e\u5bfc\u5165 MySQL \u6570\u636e\u5e93\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93<\/strong><\/p>\n<p>\u6253\u5f00 MySQL \u547d\u4ee4\u63d0\u793a\u7b26\u6216\u4f7f\u7528 MySQL GUI \u5de5\u5177\uff08\u5982 MySQL Workbench\uff09\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fde\u63a5\u5230\u60a8\u7684\u6570\u636e\u5e93\uff1a<\/p>\n<pre>mysql -u &lt;\u7528\u6237\u540d&gt; -p&lt;\u5bc6\u7801&gt; -h &lt;\u4e3b\u673a\u540d&gt; -P &lt;\u7aef\u53e3\u53f7&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u521b\u5efa\u6570\u636e\u5e93\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u8fd8\u6ca1\u6709\u521b\u5efa\u8981\u5bfc\u5165\u6570\u636e\u7684\u6570\u636e\u5e93\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u5b83\uff1a<\/p>\n<pre>CREATE DATABASE &lt;\u6570\u636e\u5e93\u540d\u79f0&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u521b\u5efa\u8868<\/strong><\/p>\n<p>\u5728\u60a8\u8981\u5bfc\u5165\u6570\u636e\u7684\u6570\u636e\u5e93\u4e2d\uff0c\u521b\u5efa\u4e00\u5f20\u8868\u6765\u5b58\u50a8\u6570\u636e\u3002\u8868\u7684\u7ed3\u6784\u5e94\u4e0e Excel \u6587\u4ef6\u4e2d\u7684\u6570\u636e\u76f8\u5339\u914d\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>CREATE TABLE my_table (\n  id INT NOT NULL AUTO_INCREMENT,\n  name VARCHAR(255),\n  age INT,\n  PRIMARY KEY (id)\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u5bfc\u51fa Excel \u6570\u636e\u4e3a CSV \u6587\u4ef6<\/strong><\/p>\n<p>\u5c06 Excel \u6570\u636e\u5bfc\u51fa\u4e3a\u9017\u53f7\u5206\u9694\u503c (CSV) \u6587\u4ef6\u3002\u5bfc\u51fa\u65f6\uff0c\u786e\u4fdd CSV \u6587\u4ef6\u7684\u5b57\u6bb5\u987a\u5e8f\u4e0e\u60a8\u521b\u5efa\u7684\u8868\u7684\u5b57\u6bb5\u987a\u5e8f\u76f8\u5339\u914d\u3002<\/p>\n<p><strong>5. \u4f7f\u7528 LOAD DATA INFILE \u52a0\u8f7d\u6570\u636e<\/strong><\/p>\n<p>\u4f7f\u7528 LOAD DATA INFILE \u8bed\u53e5\u5c06 CSV \u6587\u4ef6\u4e2d\u7684\u6570\u636e\u52a0\u8f7d\u5230 MySQL \u8868\u4e2d\u3002\u8be5\u8bed\u53e5\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>LOAD DATA INFILE '&lt;\u6587\u4ef6\u8def\u5f84&gt;'\nINTO TABLE &lt;\u8868\u540d\u79f0&gt;\nFIELDS TERMINATED BY ','\nLINES TERMINATED BY '\n'\nIGNORE 1 ROWS;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li> \u662f CSV \u6587\u4ef6\u7684\u8def\u5f84\u3002<\/li>\n<li> \u662f\u8981\u5c06\u6570\u636e\u5bfc\u5165\u5230\u7684\u8868\u540d\u79f0\u3002<\/li>\n<li>&#8216;,&#8217; \u662f\u5b57\u6bb5\u5206\u9694\u7b26\uff08\u901a\u5e38\u4e3a\u9017\u53f7\uff09\u3002<\/li>\n<li>&#8216; &#8216; \u662f\u884c\u7ec8\u6b62\u7b26\uff08\u901a\u5e38\u4e3a\u6362\u884c\u7b26\uff09\u3002<\/li>\n<li>IGNORE 1 ROWS \u5ffd\u7565 CSV \u6587\u4ef6\u4e2d\u7684\u7b2c\u4e00\u884c\uff08\u901a\u5e38\u662f\u6807\u9898\u884c\uff09\u3002<\/li>\n<\/ul>\n<p>\u6267\u884c\u6b64\u8bed\u53e5\u540e\uff0cExcel \u6570\u636e\u5c06\u5bfc\u5165\u5230 MySQL \u8868\u4e2d\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a &#8220;data.csv&#8221; \u7684 CSV \u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a<\/p>\n<pre>id,name,age\n1,John,30\n2,Jane,25\n3,Mike,40<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u5c06\u6b64\u6570\u636e\u5bfc\u5165\u540d\u4e3a &#8220;my_table&#8221; \u7684 MySQL \u8868\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>LOAD DATA INFILE '\/path\/to\/data.csv'\nINTO TABLE my_table\nFIELDS TERMINATED BY ','\nLINES TERMINATED BY '\n'\nIGNORE 1 ROWS;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u5982\u4f55\u5bfc\u5165excel\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>\u5c06 excel \u6570\u636e\u5bfc\u5165 mysql \u6570\u636e\u5e93\u53ef\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a1. \u8fde\u63a5\u6570\u636e\u5e93\uff1b2. \u521b\u5efa\u6570\u636e\u5e93\uff08\u53ef\u9009\uff09\uff1b3. \u521b\u5efa\u8868\uff1b4. \u5bfc\u51fa excel \u6570\u636e\u4e3a csv \u6587\u4ef6\uff1b5. \u4f7f\u7528 load data infile \u52a0\u8f7d\u6570\u636e\u3002 \u5982\u4f55\u5c06 Excel \u6570\u636e\u5bfc\u5165 MySQL \u6570\u636e\u5e93\uff1f \u5c06 Excel \u6570\u636e\u5bfc\u5165 MySQL \u6570\u636e\u5e93\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93 \u6253\u5f00 MySQL \u547d\u4ee4\u63d0\u793a\u7b26\u6216\u4f7f\u7528 MySQL GUI \u5de5\u5177\uff08\u5982 MySQL Workbench\uff09\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fde\u63a5\u5230\u60a8\u7684\u6570\u636e\u5e93\uff1a mysql -u &lt;\u7528\u6237\u540d&gt; -p&lt;\u5bc6\u7801&gt; -h &lt;\u4e3b\u673a\u540d&gt; -P &lt;\u7aef\u53e3\u53f7&gt; \u767b\u5f55\u540e\u590d\u5236 2. \u521b\u5efa\u6570\u636e\u5e93\uff08\u53ef\u9009\uff09 \u5982\u679c\u60a8\u8fd8\u6ca1\u6709\u521b\u5efa\u8981\u5bfc\u5165\u6570\u636e\u7684\u6570\u636e\u5e93\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u5b83\uff1a CREATE DATABASE &lt;\u6570\u636e\u5e93\u540d\u79f0&gt;; [&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-6156","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6156","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=6156"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6156\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}