{"id":6455,"date":"2024-11-14T14:30:47","date_gmt":"2024-11-14T06:30:47","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6455\/"},"modified":"2024-11-14T14:30:47","modified_gmt":"2024-11-14T06:30:47","slug":"%e6%80%8e%e4%b9%88%e6%8a%8acsv%e5%af%bc%e5%85%a5mysql%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6455\/","title":{"rendered":"\u600e\u4e48\u628acsv\u5bfc\u5165mysql\u6570\u636e\u5e93"},"content":{"rendered":"<blockquote><p>\n  \u901a\u8fc7\u4f7f\u7528 load data infile \u547d\u4ee4\uff0c\u53ef\u4ee5\u5c06 csv \u6587\u4ef6\u5bfc\u5165 mysql \u6570\u636e\u5e93\u4e2d\uff1a\u51c6\u5907 csv \u6587\u4ef6\uff1a\u786e\u4fdd\u6587\u4ef6\u683c\u5f0f\u7b26\u5408 mysql \u8bc6\u522b\u89c4\u5219\u3002\u4f7f\u7528\u547d\u4ee4\u5bfc\u5165\uff1a\u4f7f\u7528 load data infile \u547d\u4ee4\uff0c\u6307\u5b9a csv \u6587\u4ef6\u8def\u5f84\u3001\u76ee\u6807\u8868\u540d\u548c\u5b57\u6bb5\/\u884c\u5206\u9694\u7b26\u3002\u9a8c\u8bc1\u5bfc\u5165\uff1a\u4f7f\u7528 select \u67e5\u8be2\u9a8c\u8bc1\u5bfc\u5165\u662f\u5426\u6210\u529f\uff0c\u68c0\u67e5\u884c\u6570\u548c\u5b57\u6bb5\u503c\u662f\u5426\u6b63\u786e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080507493336280.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48\u628acsv\u5bfc\u5165mysql\u6570\u636e\u5e93\u63d2\u56fe\" alt=\"\u600e\u4e48\u628acsv\u5bfc\u5165mysql\u6570\u636e\u5e93\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 CSV \u6587\u4ef6\u5bfc\u5165 MySQL \u6570\u636e\u5e93<\/strong><\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u51c6\u5907 CSV \u6587\u4ef6<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd CSV \u6587\u4ef6\u4ee5 MySQL \u6570\u636e\u5e93\u53ef\u8bc6\u522b\u7684\u683c\u5f0f\u4fdd\u5b58\uff08\u4f8b\u5982\uff0c\u4ee5\u9017\u53f7\u5206\u9694\uff0c\u4f7f\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u5b57\u6bb5\u503c\uff09\u3002<\/li>\n<li>\u786e\u8ba4 CSV \u6587\u4ef6\u7684\u5217\u987a\u5e8f\u4e0e\u76ee\u6807 MySQL \u8868\u7684\u5217\u987a\u5e8f\u4e00\u81f4\u3002<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 2\uff1a\u4f7f\u7528 LOAD DATA INFILE \u547d\u4ee4<\/strong><\/p>\n<ul>\n<li>\u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\u3002<\/li>\n<li>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5bfc\u5165 CSV \u6587\u4ef6\uff1a<\/li>\n<\/ul>\n<pre>LOAD DATA INFILE '&lt;\u6587\u4ef6\u8def\u5f84&gt;' INTO TABLE &lt;\u8868\u540d&gt;\nFIELDS TERMINATED BY ','\nOPTIONALLY ENCLOSED BY '\"'\nLINES TERMINATED BY '\n'\nIGNORE 1 ROWS;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u53c2\u6570\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li>\uff1aCSV \u6587\u4ef6\u7684\u7edd\u5bf9\u6216\u76f8\u5bf9\u8def\u5f84\u3002<\/li>\n<li>\uff1a\u76ee\u6807 MySQL \u8868\u7684\u540d\u79f0\u3002<\/li>\n<li>FIELDS TERMINATED BY &#8216;,&#8217;\uff1a\u6307\u5b9a\u5b57\u6bb5\u5206\u9694\u7b26\u3002<\/li>\n<li>OPTIONALLY ENCLOSED BY &#8216;&#8221;&#8216;: \u6307\u5b9a\u5b57\u6bb5\u503c\u662f\u5426\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u3002<\/li>\n<li>LINES TERMINATED BY &#8216; &#8216;: \u6307\u5b9a\u884c\u5206\u9694\u7b26\u3002<\/li>\n<li>IGNORE 1 ROWS\uff1a\u8df3\u8fc7 CSV \u6587\u4ef6\u4e2d\u7684\u7b2c\u4e00\u884c\uff08\u901a\u5e38\u662f\u6807\u9898\u884c\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 3\uff1a\u9a8c\u8bc1\u5bfc\u5165<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 SELECT * FROM ; \u547d\u4ee4\u9a8c\u8bc1\u5bfc\u5165\u662f\u5426\u6210\u529f\u3002<\/li>\n<li>\u68c0\u67e5\u8fd4\u56de\u7684\u884c\u6570\u662f\u5426\u4e0e CSV \u6587\u4ef6\u4e2d\u7684\u884c\u6570\u4e00\u81f4\u3002<\/li>\n<li>\u68c0\u67e5\u5b57\u6bb5\u503c\u662f\u5426\u6b63\u786e\u5bfc\u5165\u3002<\/li>\n<\/ul>\n<p><strong>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u76ee\u6807 MySQL \u8868\u7684\u5b57\u6bb5\u7c7b\u578b\u4e0e CSV \u6587\u4ef6\u4e2d\u7684\u6570\u636e\u7c7b\u578b\u517c\u5bb9\u3002<\/li>\n<li>\u5982\u679c CSV \u6587\u4ef6\u4e2d\u7684\u5217\u987a\u5e8f\u4e0e\u76ee\u6807\u8868\u4e0d\u540c\uff0c\u53ef\u4ee5\u4f7f\u7528 INTO TABLE (column1, column2, &#8230;) \u8bed\u53e5\u663e\u5f0f\u6307\u5b9a\u5217\u6620\u5c04\u3002<\/li>\n<li>\u5982\u679c CSV \u6587\u4ef6\u4e2d\u6709\u7a7a\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 NULL \u6216\u5176\u4ed6\u5360\u4f4d\u7b26\u8868\u793a\u3002<\/li>\n<li>\u5bf9\u4e8e\u5927\u578b CSV \u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5206\u5757\u52a0\u8f7d\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u628acsv\u5bfc\u5165\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>\u901a\u8fc7\u4f7f\u7528 load data infile \u547d\u4ee4\uff0c\u53ef\u4ee5\u5c06 csv \u6587\u4ef6\u5bfc\u5165 mysql \u6570\u636e\u5e93\u4e2d\uff1a\u51c6\u5907 csv \u6587\u4ef6\uff1a\u786e\u4fdd\u6587\u4ef6\u683c\u5f0f\u7b26\u5408 mysql \u8bc6\u522b\u89c4\u5219\u3002\u4f7f\u7528\u547d\u4ee4\u5bfc\u5165\uff1a\u4f7f\u7528 load data infile \u547d\u4ee4\uff0c\u6307\u5b9a csv \u6587\u4ef6\u8def\u5f84\u3001\u76ee\u6807\u8868\u540d\u548c\u5b57\u6bb5\/\u884c\u5206\u9694\u7b26\u3002\u9a8c\u8bc1\u5bfc\u5165\uff1a\u4f7f\u7528 select \u67e5\u8be2\u9a8c\u8bc1\u5bfc\u5165\u662f\u5426\u6210\u529f\uff0c\u68c0\u67e5\u884c\u6570\u548c\u5b57\u6bb5\u503c\u662f\u5426\u6b63\u786e\u3002 \u5982\u4f55\u5c06 CSV \u6587\u4ef6\u5bfc\u5165 MySQL \u6570\u636e\u5e93 \u6b65\u9aa4 1\uff1a\u51c6\u5907 CSV \u6587\u4ef6 \u786e\u4fdd CSV \u6587\u4ef6\u4ee5 MySQL \u6570\u636e\u5e93\u53ef\u8bc6\u522b\u7684\u683c\u5f0f\u4fdd\u5b58\uff08\u4f8b\u5982\uff0c\u4ee5\u9017\u53f7\u5206\u9694\uff0c\u4f7f\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u5b57\u6bb5\u503c\uff09\u3002 \u786e\u8ba4 CSV \u6587\u4ef6\u7684\u5217\u987a\u5e8f\u4e0e\u76ee\u6807 MySQL \u8868\u7684\u5217\u987a\u5e8f\u4e00\u81f4\u3002 \u6b65\u9aa4 2\uff1a\u4f7f\u7528 LOAD DATA INFILE \u547d\u4ee4 \u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\u3002 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5bfc\u5165 CSV \u6587\u4ef6\uff1a LOAD DATA INFILE [&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-6455","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6455","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=6455"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6455\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}