{"id":5412,"date":"2024-11-14T08:13:01","date_gmt":"2024-11-14T00:13:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5412\/"},"modified":"2024-11-14T08:13:01","modified_gmt":"2024-11-14T00:13:01","slug":"mysql%e6%80%8e%e4%b9%88%e5%af%bc%e5%85%a5%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5412\/","title":{"rendered":"mysql\u600e\u4e48\u5bfc\u5165\u6570\u636e\u5e93\u7684\u6587\u4ef6"},"content":{"rendered":"<blockquote><p>\n  mysql\u6570\u636e\u5e93\u6587\u4ef6\u5bfc\u5165\u6b65\u9aa4\uff1a\u8fde\u63a5\u6570\u636e\u5e93\u5e76\u9009\u62e9\u76ee\u6807\u6570\u636e\u5e93\uff1b\u4f7f\u7528load data infile\u8bed\u53e5\u4ece\u6587\u4ef6\u4e2d\u5bfc\u5165\u6570\u636e\uff0c\u6307\u5b9a\u6587\u4ef6\u8def\u5f84\u3001\u8868\u540d\u3001\u5206\u9694\u7b26\u548c\u884c\u5206\u9694\u7b26\u7b49\u53c2\u6570\uff0c\u793a\u4f8b\uff1aload data infile &#8216;\/path\/to\/sample_data.csv&#8217; into table user_data fields terminated by &#8216;,&#8217; enclosed by &#8216;&#8221;&#8216; lines terminated by &#8216; &#8216;\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052811422429747.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u5bfc\u5165\u6570\u636e\u5e93\u7684\u6587\u4ef6\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u5bfc\u5165\u6570\u636e\u5e93\u7684\u6587\u4ef6\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u5bfc\u5165\u6570\u636e\u5e93\u6587\u4ef6<\/strong><\/p>\n<p><strong>\u5982\u4f55\u5bfc\u5165\u6570\u636e\u5e93\u6587\u4ef6\uff1f<\/strong><\/p>\n<p>\u5bfc\u5165\u6570\u636e\u5e93\u6587\u4ef6\u5230 MySQL \u6570\u636e\u5e93\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a<\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u8fde\u63a5\u5230\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u4f7f\u7528 MySQL \u547d\u4ee4\u884c\u5ba2\u6237\u7aef\u6216\u5176\u4ed6\u6570\u636e\u5e93\u5de5\u5177\u8fde\u63a5\u5230\u9700\u8981\u5bfc\u5165\u6570\u636e\u7684\u6570\u636e\u5e93\u3002<\/p>\n<p><strong>\u6b65\u9aa4 2\uff1a\u9009\u62e9\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u4f7f\u7528 USE \u8bed\u53e5\u9009\u62e9\u8981\u5bfc\u5165\u6570\u636e\u7684\u76ee\u6807\u6570\u636e\u5e93\u3002<\/p>\n<p><strong>\u6b65\u9aa4 3\uff1a\u5bfc\u5165\u6570\u636e\u6587\u4ef6<\/strong><\/p>\n<p>\u4f7f\u7528 LOAD DATA INFILE \u8bed\u53e5\u4ece\u6587\u4ef6\u5bfc\u5165\u6570\u636e\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>LOAD DATA INFILE '&lt;\u6587\u4ef6\u8def\u5f84&gt;'\nINTO TABLE &lt;\u8868\u540d&gt;\nFIELDS TERMINATED BY '&lt;\u5206\u9694\u7b26&gt;'\n[ENCLOSED BY '&lt;\u5305\u56f4\u7b26&gt;']\n[LINES TERMINATED BY '&lt;\u884c\u5206\u9694\u7b26&gt;']\n[IGNORE &lt;\u884c\u6570&gt;]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u53c2\u6570\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li>\uff1a\u8981\u5bfc\u5165\u7684\u6570\u636e\u6587\u4ef6\u8def\u5f84\u3002<\/li>\n<li>\uff1a\u8981\u5bfc\u5165\u6570\u636e\u7684\u76ee\u6807\u8868\u540d\u3002<\/li>\n<li>\uff1a\u5b57\u6bb5\u5206\u9694\u7b26\u3002<\/li>\n<li>\uff08\u53ef\u9009\uff09\uff1a\u5b57\u6bb5\u5305\u56f4\u7b26\u3002<\/li>\n<li>\uff08\u53ef\u9009\uff09\uff1a\u884c\u5206\u9694\u7b26\uff0c\u9ed8\u8ba4\u4e3a\u6362\u884c\u7b26\u3002<\/li>\n<li>\uff08\u53ef\u9009\uff09\uff1a\u5ffd\u7565\u5bfc\u5165\u6587\u4ef6\u4e2d\u7684\u6307\u5b9a\u884c\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u5bfc\u5165\u540d\u4e3a sample_data.csv \u7684 CSV \u6587\u4ef6\u5230 mydb \u6570\u636e\u5e93\u4e2d\u7684 user_data \u8868\uff1a<\/p>\n<pre>LOAD DATA INFILE '\/path\/to\/sample_data.csv'\nINTO TABLE user_data\nFIELDS TERMINATED BY ','\nENCLOSED BY '\"'\nLINES TERMINATED BY '\n'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5176\u4ed6\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u6570\u636e\u6587\u4ef6\u683c\u5f0f\u4e0e\u76ee\u6807\u8868\u7ed3\u6784\u517c\u5bb9\u3002<\/li>\n<li>\u5982\u679c\u6587\u4ef6\u5f88\u5927\uff0c\u53ef\u4ee5\u5206\u6279\u5bfc\u5165\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<li>\u4f7f\u7528 SHOW WARNINGS \u547d\u4ee4\u67e5\u770b\u5bfc\u5165\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u7684\u4efb\u4f55\u8b66\u544a\u6216\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5bfc\u5165\u6570\u636e\u5e93\u7684\u6587\u4ef6\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>mysql\u6570\u636e\u5e93\u6587\u4ef6\u5bfc\u5165\u6b65\u9aa4\uff1a\u8fde\u63a5\u6570\u636e\u5e93\u5e76\u9009\u62e9\u76ee\u6807\u6570\u636e\u5e93\uff1b\u4f7f\u7528load data infile\u8bed\u53e5\u4ece\u6587\u4ef6\u4e2d\u5bfc\u5165\u6570\u636e\uff0c\u6307\u5b9a\u6587\u4ef6\u8def\u5f84\u3001\u8868\u540d\u3001\u5206\u9694\u7b26\u548c\u884c\u5206\u9694\u7b26\u7b49\u53c2\u6570\uff0c\u793a\u4f8b\uff1aload data infile &#8216;\/path\/to\/sample_data.csv&#8217; into table user_data fields terminated by &#8216;,&#8217; enclosed by &#8216;&#8221;&#8216; lines terminated by &#8216; &#8216;\u3002 MySQL \u5bfc\u5165\u6570\u636e\u5e93\u6587\u4ef6 \u5982\u4f55\u5bfc\u5165\u6570\u636e\u5e93\u6587\u4ef6\uff1f \u5bfc\u5165\u6570\u636e\u5e93\u6587\u4ef6\u5230 MySQL \u6570\u636e\u5e93\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a \u6b65\u9aa4 1\uff1a\u8fde\u63a5\u5230\u6570\u636e\u5e93 \u4f7f\u7528 MySQL \u547d\u4ee4\u884c\u5ba2\u6237\u7aef\u6216\u5176\u4ed6\u6570\u636e\u5e93\u5de5\u5177\u8fde\u63a5\u5230\u9700\u8981\u5bfc\u5165\u6570\u636e\u7684\u6570\u636e\u5e93\u3002 \u6b65\u9aa4 2\uff1a\u9009\u62e9\u6570\u636e\u5e93 \u4f7f\u7528 USE \u8bed\u53e5\u9009\u62e9\u8981\u5bfc\u5165\u6570\u636e\u7684\u76ee\u6807\u6570\u636e\u5e93\u3002 \u6b65\u9aa4 3\uff1a\u5bfc\u5165\u6570\u636e\u6587\u4ef6 \u4f7f\u7528 LOAD DATA INFILE \u8bed\u53e5\u4ece\u6587\u4ef6\u5bfc\u5165\u6570\u636e\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a LOAD DATA INFILE &#8216;&lt;\u6587\u4ef6\u8def\u5f84&gt;&#8217; INTO TABLE &lt;\u8868\u540d&gt; FIELDS TERMINATED BY &#8216;&lt;\u5206\u9694\u7b26&gt;&#8217; [&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-5412","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5412","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=5412"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5412\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}