{"id":6449,"date":"2024-11-14T13:03:08","date_gmt":"2024-11-14T05:03:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6449\/"},"modified":"2024-11-14T13:03:08","modified_gmt":"2024-11-14T05:03:08","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%80%8e%e4%b9%88%e5%af%bc%e5%85%a5%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6449\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u600e\u4e48\u5bfc\u5165\u6570\u636e"},"content":{"rendered":"<blockquote><p>\n  \u5bfc\u5165 mysql \u6570\u636e\u6709\u51e0\u79cd\u65b9\u6cd5\uff0c\u6700\u5e38\u7528\u7684\u662f\uff1aload data infile &#8216;file.csv&#8217; into table table_name;\u6b65\u9aa4\uff1a\u51c6\u5907 csv \u6570\u636e\u6587\u4ef6\u3002\u8fde\u63a5\u5230\u6570\u636e\u5e93\u5e76\u9009\u62e9\u8981\u5bfc\u5165\u6570\u636e\u7684\u6570\u636e\u5e93\u548c\u8868\u3002\u6267\u884c\u5bfc\u5165\u547d\u4ee4\uff0c\u5176\u4e2d &#8216;file.csv&#8217; \u662f csv \u6587\u4ef6\u8def\u5f84\uff0ctable_name \u662f\u76ee\u6807\u8868\u540d\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080507401133061.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5bfc\u5165\u6570\u636e\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u600e\u4e48\u5bfc\u5165\u6570\u636e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 MySQL \u6570\u636e\u5e93\u4e2d\u5bfc\u5165\u6570\u636e<\/strong><\/p>\n<p><strong>\u5bfc\u5165\u65b9\u6cd5<\/strong><\/p>\n<p>\u5bfc\u5165 MySQL \u6570\u636e\u5e93\u6570\u636e\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4f46\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>LOAD DATA INFILE 'file.csv' INTO TABLE table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4<\/strong><\/p>\n<ol>\n<li> <strong>\u51c6\u5907\u6570\u636e\u6587\u4ef6\uff1a<\/strong> \u5c06\u8981\u5bfc\u5165\u7684\u6570\u636e\u5bfc\u51fa\u4e3a CSV\uff08\u9017\u53f7\u5206\u9694\u503c\uff09\u6587\u4ef6\u3002\u786e\u4fdd\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u4e0e\u76ee\u6807\u8868\u4e2d\u7684\u5217\u5bf9\u5e94\u3002<\/li>\n<li> <strong>\u8fde\u63a5\u5230 MySQL\uff1a<\/strong> \u4f7f\u7528\u547d\u4ee4\u884c\u6216 MySQL Workbench \u7b49\u5ba2\u6237\u7aef\u5de5\u5177\u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\u3002<\/li>\n<li> <strong>\u9009\u62e9\u6570\u636e\u5e93\u548c\u8868\uff1a<\/strong> \u5728\u8fde\u63a5\u5230\u6570\u636e\u5e93\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9009\u62e9\u8981\u5bfc\u5165\u6570\u636e\u7684\u6570\u636e\u5e93\u548c\u8868\uff1a<\/li>\n<\/ol>\n<pre>USE database_name;\nSELECT table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li> <strong>\u6267\u884c\u5bfc\u5165\u547d\u4ee4\uff1a<\/strong> \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5bfc\u5165\u6570\u636e\uff1a<\/li>\n<\/ol>\n<pre>LOAD DATA INFILE 'file.csv' INTO TABLE table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>file.csv \u662f\u8981\u5bfc\u5165\u7684 CSV \u6587\u4ef6\u7684\u8def\u5f84\u3002<\/li>\n<li>table_name \u662f\u8981\u5bfc\u5165\u6570\u636e\u7684\u8868\u540d\u3002<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd CSV \u6587\u4ef6\u4e2d\u7684\u5217\u987a\u5e8f\u4e0e\u8868\u4e2d\u7684\u5217\u987a\u5e8f\u5339\u914d\u3002<\/li>\n<li>\u5982\u679c CSV \u6587\u4ef6\u4e2d\u5305\u542b\u7a7a\u503c\uff0c\u8bf7\u4f7f\u7528 NULL \u6765\u8868\u793a\u5b83\u4eec\u3002<\/li>\n<li>\u5bfc\u5165\u64cd\u4f5c\u4f1a\u8986\u76d6\u8868\u4e2d\u73b0\u6709\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<p><strong>\u5176\u4ed6\u5bfc\u5165\u65b9\u6cd5<\/strong><\/p>\n<p>\u9664\u4e86 LOAD DATA INFILE \u547d\u4ee4\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u5bfc\u5165\u6570\u636e\uff1a<\/p>\n<ul>\n<li> <strong>INSERT \u8bed\u53e5\uff1a<\/strong> \u4f7f\u7528 INSERT \u8bed\u53e5\u9010\u4e2a\u63d2\u5165\u8bb0\u5f55\u3002<\/li>\n<li> <strong>MySQL Workbench \u5bfc\u5165\u5411\u5bfc\uff1a<\/strong> \u4f7f\u7528 MySQL Workbench \u7684\u5bfc\u5165\u5411\u5bfc\u5c06\u6570\u636e\u4ece CSV \u6587\u4ef6\u5bfc\u5165\u5230\u6570\u636e\u5e93\u3002<\/li>\n<li> <strong>\u7b2c\u4e09\u65b9\u5de5\u5177\uff1a<\/strong> \u6709\u8bb8\u591a\u7b2c\u4e09\u65b9\u5de5\u5177\u53ef\u4ee5\u7528\u6765\u5bfc\u5165\u6570\u636e\u5230 MySQL \u6570\u636e\u5e93\u4e2d\uff0c\u4f8b\u5982 Navicat \u548c Sequel Pro\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u600e\u4e48\u5bfc\u5165\u6570\u636e\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>\u5bfc\u5165 mysql \u6570\u636e\u6709\u51e0\u79cd\u65b9\u6cd5\uff0c\u6700\u5e38\u7528\u7684\u662f\uff1aload data infile &#8216;file.csv&#8217; into table table_name;\u6b65\u9aa4\uff1a\u51c6\u5907 csv \u6570\u636e\u6587\u4ef6\u3002\u8fde\u63a5\u5230\u6570\u636e\u5e93\u5e76\u9009\u62e9\u8981\u5bfc\u5165\u6570\u636e\u7684\u6570\u636e\u5e93\u548c\u8868\u3002\u6267\u884c\u5bfc\u5165\u547d\u4ee4\uff0c\u5176\u4e2d &#8216;file.csv&#8217; \u662f csv \u6587\u4ef6\u8def\u5f84\uff0ctable_name \u662f\u76ee\u6807\u8868\u540d\u3002 \u5982\u4f55\u5728 MySQL \u6570\u636e\u5e93\u4e2d\u5bfc\u5165\u6570\u636e \u5bfc\u5165\u65b9\u6cd5 \u5bfc\u5165 MySQL \u6570\u636e\u5e93\u6570\u636e\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4f46\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a LOAD DATA INFILE &#8216;file.csv&#8217; INTO TABLE table_name; \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 \u51c6\u5907\u6570\u636e\u6587\u4ef6\uff1a \u5c06\u8981\u5bfc\u5165\u7684\u6570\u636e\u5bfc\u51fa\u4e3a CSV\uff08\u9017\u53f7\u5206\u9694\u503c\uff09\u6587\u4ef6\u3002\u786e\u4fdd\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u4e0e\u76ee\u6807\u8868\u4e2d\u7684\u5217\u5bf9\u5e94\u3002 \u8fde\u63a5\u5230 MySQL\uff1a \u4f7f\u7528\u547d\u4ee4\u884c\u6216 MySQL Workbench \u7b49\u5ba2\u6237\u7aef\u5de5\u5177\u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\u3002 \u9009\u62e9\u6570\u636e\u5e93\u548c\u8868\uff1a \u5728\u8fde\u63a5\u5230\u6570\u636e\u5e93\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9009\u62e9\u8981\u5bfc\u5165\u6570\u636e\u7684\u6570\u636e\u5e93\u548c\u8868\uff1a USE database_name; SELECT table_name; \u767b\u5f55\u540e\u590d\u5236 \u6267\u884c\u5bfc\u5165\u547d\u4ee4\uff1a \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5bfc\u5165\u6570\u636e\uff1a LOAD DATA [&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-6449","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6449","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=6449"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6449\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}