{"id":6551,"date":"2024-11-14T09:58:10","date_gmt":"2024-11-14T01:58:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6551\/"},"modified":"2024-11-14T09:58:10","modified_gmt":"2024-11-14T01:58:10","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%80%8e%e4%b9%88%e5%af%bc%e5%87%bacsv","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6551\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u600e\u4e48\u5bfc\u51facsv"},"content":{"rendered":"<blockquote><p>\n  \u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 select into outfile \u8bed\u53e5\u4ece mysql \u6570\u636e\u5e93\u5bfc\u51fa csv \u6587\u4ef6\uff1a\u8fde\u63a5\u5230\u6570\u636e\u5e93\u3002\u9009\u62e9\u8981\u5bfc\u51fa\u7684\u6570\u636e\u5e93\u3002\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u5bfc\u51fa\u6570\u636e\uff1aselect * into outfile &#8216;path\/to\/file.csv&#8217; fields terminated by &#8216;,&#8217; optionally enclosed by &#8216;&#8221;&#8216; lines terminated by &#8216; &#8216;;\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080520160252369.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5bfc\u51facsv\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5bfc\u51facsv\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 MySQL \u6570\u636e\u5e93\u4e2d\u5bfc\u51fa CSV<\/strong><\/p>\n<p><strong>\u5bfc\u51fa CSV \u6587\u4ef6<\/strong><\/p>\n<p>\u8981\u4ece MySQL \u6570\u636e\u5e93\u5bfc\u51fa CSV \u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li> <strong>\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff1a<\/strong>\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u6216 GUI \u5ba2\u6237\u7aef\u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\u3002<\/li>\n<li> <strong>\u9009\u62e9\u6570\u636e\u5e93\uff1a<\/strong>\u4f7f\u7528 USE \u547d\u4ee4\u9009\u62e9\u8981\u4ece\u4e2d\u5bfc\u51fa\u6570\u636e\u7684\u6570\u636e\u5e93\u3002<\/li>\n<li> <strong>\u4f7f\u7528 SELECT INTO OUTFILE \u8bed\u53e5\uff1a<\/strong>\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u5bfc\u51fa\u6570\u636e\u5230 CSV \u6587\u4ef6\uff1a<\/li>\n<\/ol>\n<pre>SELECT * INTO OUTFILE 'path\/to\/file.csv'\nFIELDS TERMINATED BY ','\nOPTIONALLY ENCLOSED BY '\"'\nLINES TERMINATED BY '\n';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>path\/to\/file.csv \u662f\u5bfc\u51fa\u7684 CSV \u6587\u4ef6\u7684\u8def\u5f84\u548c\u540d\u79f0\u3002<\/li>\n<li>FIELDS TERMINATED BY &#8216;,&#8217; \u6307\u5b9a\u5b57\u6bb5\u5206\u9694\u7b26\uff08\u5728\u6b64\u4f8b\u4e2d\u4e3a\u9017\u53f7\uff09\u3002<\/li>\n<li>OPTIONALLY ENCLOSED BY &#8216;&#8221;&#8216;\uff08\u53ef\u9009\uff09\u6307\u5b9a\u5b57\u6bb5\u662f\u5426\u7528\u5f15\u53f7\u62ec\u8d77\u6765\u3002<\/li>\n<li>LINES TERMINATED BY &#8216; &#8216; \u6307\u5b9a\u884c\u5206\u9694\u7b26\uff08\u5728\u6b64\u4f8b\u4e2d\u4e3a\u65b0\u884c\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u5c06 users \u8868\u4e2d\u7684\u6570\u636e\u5bfc\u51fa\u5230\u540d\u4e3a users.csv \u7684 CSV \u6587\u4ef6\uff1a<\/p>\n<pre>USE my_database;\nSELECT * INTO OUTFILE '\/path\/to\/users.csv'\nFIELDS TERMINATED BY ','\nOPTIONALLY ENCLOSED BY '\"'\nLINES TERMINATED BY '\n';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u5728\u5bfc\u51fa\u8def\u5f84\u4e0a\u5177\u6709\u5199\u5165\u6743\u9650\u3002<\/li>\n<li>\u5982\u679c\u6570\u636e\u5305\u542b\u7279\u6b8a\u5b57\u7b26\uff08\u5982\u9017\u53f7\u6216\u53cc\u5f15\u53f7\uff09\uff0c\u8bf7\u76f8\u5e94\u5730\u8c03\u6574\u5206\u9694\u7b26\u9009\u9879\u3002<\/li>\n<li>\u5bfc\u51fa\u7684 CSV \u6587\u4ef6\u53ef\u4ee5\u8f7b\u677e\u5bfc\u5165\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u6216\u5c06\u5176\u7528\u4e8e\u6570\u636e\u5206\u6790\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u600e\u4e48\u5bfc\u51facsv\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>\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 select into outfile \u8bed\u53e5\u4ece mysql \u6570\u636e\u5e93\u5bfc\u51fa csv \u6587\u4ef6\uff1a\u8fde\u63a5\u5230\u6570\u636e\u5e93\u3002\u9009\u62e9\u8981\u5bfc\u51fa\u7684\u6570\u636e\u5e93\u3002\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u5bfc\u51fa\u6570\u636e\uff1aselect * into outfile &#8216;path\/to\/file.csv&#8217; fields terminated by &#8216;,&#8217; optionally enclosed by &#8216;&#8221;&#8216; lines terminated by &#8216; &#8216;; \u5982\u4f55\u5728 MySQL \u6570\u636e\u5e93\u4e2d\u5bfc\u51fa CSV \u5bfc\u51fa CSV \u6587\u4ef6 \u8981\u4ece MySQL \u6570\u636e\u5e93\u5bfc\u51fa CSV \u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u8fde\u63a5\u5230\u6570\u636e\u5e93\uff1a\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u6216 GUI \u5ba2\u6237\u7aef\u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\u3002 \u9009\u62e9\u6570\u636e\u5e93\uff1a\u4f7f\u7528 USE \u547d\u4ee4\u9009\u62e9\u8981\u4ece\u4e2d\u5bfc\u51fa\u6570\u636e\u7684\u6570\u636e\u5e93\u3002 \u4f7f\u7528 SELECT INTO OUTFILE \u8bed\u53e5\uff1a\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u5bfc\u51fa\u6570\u636e\u5230 CSV \u6587\u4ef6\uff1a SELECT * [&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-6551","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6551","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=6551"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6551\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}