{"id":6558,"date":"2024-11-14T08:11:18","date_gmt":"2024-11-14T00:11:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6558\/"},"modified":"2024-11-14T08:11:18","modified_gmt":"2024-11-14T00:11:18","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e8%a1%a8%e6%a0%bc%e6%80%8e%e4%b9%88%e5%af%bc%e5%87%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6558\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u8868\u683c\u600e\u4e48\u5bfc\u51fa"},"content":{"rendered":"<blockquote><p>\n  \u53ef\u4ee5\u5bfc\u51fa mysql \u8868\u683c\u4ee5\u8fdb\u884c\u5907\u4efd\u3001\u8fc1\u79fb\u6216\u5206\u6790\u6570\u636e\u3002\u6b65\u9aa4\u5305\u62ec\uff1a\u767b\u5f55 mysql \u6570\u636e\u5e93\u3002\u9009\u62e9\u8981\u4ece\u4e2d\u5bfc\u51fa\u8868\u683c\u7684\u6570\u636e\u5e93\u3002\u4f7f\u7528 select into outfile \u8bed\u53e5\u5bfc\u51fa\u8868\u683c\u5230\u6587\u4ef6\u4e2d\uff0c\u6307\u5b9a\u5217\u5206\u9694\u7b26\u3001\u5b57\u6bb5\u5206\u9694\u7b26\u548c\u884c\u5206\u9694\u7b26\u3002\uff08\u53ef\u9009\uff09\u4e3a\u5bfc\u51fa\u6587\u4ef6\u8bbe\u7f6e\u9002\u5f53\u7684\u6743\u9650\u3002\u6267\u884c\u67e5\u8be2\u4ee5\u5bfc\u51fa\u8868\u683c\u3002\u9a8c\u8bc1\u5bfc\u51fa\u7684\u6587\u4ef6\u662f\u5426\u5305\u542b\u6240\u6709\u9884\u671f\u7684\u6570\u636e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080520224092568.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u8868\u683c\u600e\u4e48\u5bfc\u51fa\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u8868\u683c\u600e\u4e48\u5bfc\u51fa\u63d2\u56fe\" \/><\/p>\n<h2>\u5982\u4f55\u5bfc\u51fa MySQL \u6570\u636e\u5e93\u8868\u683c<\/h2>\n<p>\u5bfc\u51fa MySQL \u6570\u636e\u5e93\u8868\u683c\u53ef\u4ee5\u5e2e\u52a9\u5907\u4efd\u6570\u636e\u3001\u8fc1\u79fb\u6570\u636e\u5230\u53e6\u4e00\u4e2a\u6570\u636e\u5e93\u6216\u8fdb\u884c\u6570\u636e\u5206\u6790\u3002\u672c\u6587\u5c06\u4e00\u6b65\u6b65\u6307\u5bfc\u60a8\u5bfc\u51fa MySQL \u8868\u683c\u3002<\/p>\n<h3>\u6b65\u9aa4\uff1a<\/h3>\n<p><strong>1. \u767b\u5f55 MySQL<\/strong><\/p>\n<p>\u4f7f\u7528\u547d\u4ee4\u884c\u6216\u56fe\u5f62\u754c\u9762\u8f6f\u4ef6\uff08\u5982 MySQL Workbench\uff09\u767b\u5f55\u5230 MySQL \u6570\u636e\u5e93\u3002<\/p>\n<p><strong>2. \u9009\u62e9\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u4f7f\u7528 USE \u547d\u4ee4\u9009\u62e9\u60a8\u8981\u4ece\u4e2d\u5bfc\u51fa\u8868\u683c\u7684\u6570\u636e\u5e93\uff1a<\/p>\n<pre>USE your_database_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u5bfc\u51fa\u8868\u683c<\/strong><\/p>\n<p>\u4f7f\u7528 SELECT INTO OUTFILE \u8bed\u53e5\u5c06\u8868\u683c\u5bfc\u51fa\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff1a<\/p>\n<pre>SELECT *  \nINTO OUTFILE '\/path\/to\/exported_file.csv'  \nFIELDS TERMINATED BY ','  \nENCLOSED BY '\"'  \nLINES TERMINATED BY '\n';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>* \u8868\u793a\u5bfc\u51fa\u6240\u6709\u5217<\/li>\n<li>\/path\/to\/exported_file.csv \u662f\u5bfc\u51fa\u6587\u4ef6\u7684\u8def\u5f84\u548c\u540d\u79f0<\/li>\n<li>, \u6307\u5b9a\u5217\u5206\u9694\u7b26<\/li>\n<li>&#8221; \u6307\u5b9a\u5b57\u6bb5\u5206\u9694\u7b26<\/li>\n<li> \u6307\u5b9a\u884c\u5206\u9694\u7b26<\/li>\n<\/ul>\n<p><strong>4. \u8bbe\u7f6e\u6743\u9650\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u8981\u5bfc\u51fa\uff0c\u60a8\u9700\u8981\u4e3a\u5bfc\u51fa\u6587\u4ef6\u8bbe\u7f6e\u9002\u5f53\u7684\u6743\u9650\uff1a<\/p>\n<pre>chmod 600 \/path\/to\/exported_file.csv<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u6267\u884c\u67e5\u8be2<\/strong><\/p>\n<p>\u6267\u884c SELECT INTO OUTFILE \u67e5\u8be2\u4ee5\u5bfc\u51fa\u8868\u683c\uff1a<\/p>\n<pre>QUERY OK, 1000 rows affected (1.22 sec)\nRecords: 1000  Duplicates: 0  Warnings: 0<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u9a8c\u8bc1\u5bfc\u51fa<\/strong><\/p>\n<p>\u68c0\u67e5\u5bfc\u51fa\u7684\u6587\u4ef6\u4ee5\u9a8c\u8bc1\u5b83\u662f\u5426\u5305\u542b\u60a8\u9884\u671f\u7684\u6240\u6709\u6570\u636e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u8868\u683c\u600e\u4e48\u5bfc\u51fa\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\u5bfc\u51fa mysql \u8868\u683c\u4ee5\u8fdb\u884c\u5907\u4efd\u3001\u8fc1\u79fb\u6216\u5206\u6790\u6570\u636e\u3002\u6b65\u9aa4\u5305\u62ec\uff1a\u767b\u5f55 mysql \u6570\u636e\u5e93\u3002\u9009\u62e9\u8981\u4ece\u4e2d\u5bfc\u51fa\u8868\u683c\u7684\u6570\u636e\u5e93\u3002\u4f7f\u7528 select into outfile \u8bed\u53e5\u5bfc\u51fa\u8868\u683c\u5230\u6587\u4ef6\u4e2d\uff0c\u6307\u5b9a\u5217\u5206\u9694\u7b26\u3001\u5b57\u6bb5\u5206\u9694\u7b26\u548c\u884c\u5206\u9694\u7b26\u3002\uff08\u53ef\u9009\uff09\u4e3a\u5bfc\u51fa\u6587\u4ef6\u8bbe\u7f6e\u9002\u5f53\u7684\u6743\u9650\u3002\u6267\u884c\u67e5\u8be2\u4ee5\u5bfc\u51fa\u8868\u683c\u3002\u9a8c\u8bc1\u5bfc\u51fa\u7684\u6587\u4ef6\u662f\u5426\u5305\u542b\u6240\u6709\u9884\u671f\u7684\u6570\u636e\u3002 \u5982\u4f55\u5bfc\u51fa MySQL \u6570\u636e\u5e93\u8868\u683c \u5bfc\u51fa MySQL \u6570\u636e\u5e93\u8868\u683c\u53ef\u4ee5\u5e2e\u52a9\u5907\u4efd\u6570\u636e\u3001\u8fc1\u79fb\u6570\u636e\u5230\u53e6\u4e00\u4e2a\u6570\u636e\u5e93\u6216\u8fdb\u884c\u6570\u636e\u5206\u6790\u3002\u672c\u6587\u5c06\u4e00\u6b65\u6b65\u6307\u5bfc\u60a8\u5bfc\u51fa MySQL \u8868\u683c\u3002 \u6b65\u9aa4\uff1a 1. \u767b\u5f55 MySQL \u4f7f\u7528\u547d\u4ee4\u884c\u6216\u56fe\u5f62\u754c\u9762\u8f6f\u4ef6\uff08\u5982 MySQL Workbench\uff09\u767b\u5f55\u5230 MySQL \u6570\u636e\u5e93\u3002 2. \u9009\u62e9\u6570\u636e\u5e93 \u4f7f\u7528 USE \u547d\u4ee4\u9009\u62e9\u60a8\u8981\u4ece\u4e2d\u5bfc\u51fa\u8868\u683c\u7684\u6570\u636e\u5e93\uff1a USE your_database_name; \u767b\u5f55\u540e\u590d\u5236 3. \u5bfc\u51fa\u8868\u683c \u4f7f\u7528 SELECT INTO OUTFILE \u8bed\u53e5\u5c06\u8868\u683c\u5bfc\u51fa\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff1a SELECT * INTO OUTFILE &#8216;\/path\/to\/exported_file.csv&#8217; FIELDS TERMINATED BY &#8216;,&#8217; ENCLOSED BY &#8216;&#8221;&#8216; LINES TERMINATED [&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-6558","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6558","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=6558"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6558\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}