{"id":6450,"date":"2024-11-14T08:19:16","date_gmt":"2024-11-14T00:19:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6450\/"},"modified":"2024-11-14T08:19:16","modified_gmt":"2024-11-14T00:19:16","slug":"%e6%80%8e%e4%b9%88%e6%8a%8a%e6%95%b0%e6%8d%ae%e5%ba%93%e5%af%bc%e5%85%a5mysql","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6450\/","title":{"rendered":"\u600e\u4e48\u628a\u6570\u636e\u5e93\u5bfc\u5165mysql"},"content":{"rendered":"<blockquote><p>\n  \u5bfc\u5165\u6570\u636e\u5e93\u5230 mysql \u5206\u4e94\u6b65\u5b8c\u6210\uff1a\u521b\u5efa\u6570\u636e\u5e93\u51c6\u5907\u6570\u636e\u6e90\u4f7f\u7528 load data infile \u547d\u4ee4\u8bbe\u7f6e\u5bfc\u5165\u9009\u9879\uff08\u53ef\u9009\uff09\u6267\u884c\u5bfc\u5165\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/05\/2024080507403730761.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48\u628a\u6570\u636e\u5e93\u5bfc\u5165mysql\u63d2\u56fe\" alt=\"\u600e\u4e48\u628a\u6570\u636e\u5e93\u5bfc\u5165mysql\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06\u6570\u636e\u5e93\u5bfc\u5165 MySQL<\/strong><\/p>\n<p>\u5bfc\u5165\u6570\u636e\u5e93\u5230 MySQL \u662f\u4e00\u4e2a\u5c06\u5916\u90e8\u6570\u636e\u6e90\u7684\u6570\u636e\u79fb\u52a8\u5230 MySQL \u6570\u636e\u5e93\u7684\u8fc7\u7a0b\u3002\u4ee5\u4e0b\u662f\u5bfc\u5165\u6570\u636e\u5e93\u5230 MySQL \u7684\u5206\u6b65\u6307\u5357\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u5728\u5bfc\u5165\u6570\u636e\u4e4b\u524d\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u8981\u63a5\u6536\u6570\u636e\u7684\u6570\u636e\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5728 MySQL \u4e2d\u521b\u5efa\u6570\u636e\u5e93\uff1a<\/p>\n<pre>CREATE DATABASE database_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d database_name \u662f\u8981\u521b\u5efa\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002<\/p>\n<p><strong>2. \u51c6\u5907\u6570\u636e\u6e90<\/strong><\/p>\n<p>\u5c06\u6570\u636e\u5bfc\u5165 MySQL \u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u6570\u636e\u6e90\u4ee5\u53ef\u4f9b MySQL \u8bc6\u522b\u7684\u683c\u5f0f\u5b58\u5728\u3002\u8fd9\u901a\u5e38\u6d89\u53ca\u5c06\u6e90\u6570\u636e\u5bfc\u51fa\u4e3a SQL \u517c\u5bb9\u7684\u683c\u5f0f\uff0c\u4f8b\u5982 CSV\u3001SQL \u8f6c\u50a8\u6216 XML\u3002<\/p>\n<p><strong>3. \u4f7f\u7528 MySQL \u5bfc\u5165\u547d\u4ee4<\/strong><\/p>\n<p>MySQL \u4e2d\u63d0\u4f9b\u4e86\u51e0\u4e2a\u547d\u4ee4\u7528\u4e8e\u5bfc\u5165\u6570\u636e\uff0c\u6700\u5e38\u7528\u7684\u547d\u4ee4\u662f LOAD DATA INFILE\uff1a<\/p>\n<pre>LOAD DATA INFILE 'file_path' INTO TABLE table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>file_path \u662f\u6e90\u6570\u636e\u7684\u8def\u5f84\u3002<\/li>\n<li>table_name \u662f\u8981\u5c06\u6570\u636e\u5bfc\u5165\u5230\u7684\u8868\u7684\u540d\u79f0\u3002<\/li>\n<\/ul>\n<p><strong>4. \u8bbe\u7f6e\u5bfc\u5165\u9009\u9879<\/strong><\/p>\n<p>\u5728\u5bfc\u5165\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u4ee5\u4e0b\u9009\u9879\u6765\u5b9a\u5236\u5bfc\u5165\u884c\u4e3a\uff1a<\/p>\n<ul>\n<li> <strong>FIELDS TERMINATED BY<\/strong>\uff1a\u6307\u5b9a\u5206\u9694\u6570\u636e\u5b57\u6bb5\u7684\u5b57\u7b26\u3002<\/li>\n<li> <strong>LINES TERMINATED BY<\/strong>\uff1a\u6307\u5b9a\u5206\u9694\u6570\u636e\u884c\u7684\u5b57\u7b26\u3002<\/li>\n<li> <strong>IGNORE<\/strong>\uff1a\u8df3\u8fc7\u5177\u6709\u65e0\u6548\u503c\u7684\u8bb0\u5f55\u3002<\/li>\n<li> <strong>CHARACTER SET<\/strong>\uff1a\u6307\u5b9a\u5bfc\u5165\u6570\u636e\u7684\u5b57\u7b26\u96c6\u3002<\/li>\n<\/ul>\n<p><strong>5. \u6267\u884c\u5bfc\u5165<\/strong><\/p>\n<p>\u51c6\u5907\u597d\u5bfc\u5165\u547d\u4ee4\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6267\u884c\u5bfc\u5165\uff1a<\/p>\n<pre>mysql -u username -p password database_name &lt; import_command&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>username \u662f MySQL \u7528\u6237\u540d\u3002<\/li>\n<li>password \u662f MySQL \u5bc6\u7801\u3002<\/li>\n<li>database_name \u662f\u8981\u5bfc\u5165\u6570\u636e\u7684\u6570\u636e\u5e93\u3002<\/li>\n<li>import_command \u662f\u5305\u542b LOAD DATA INFILE \u547d\u4ee4\u7684\u6587\u672c\u6587\u4ef6\u6216\u7ba1\u9053\u3002<\/li>\n<\/ul>\n<p>\u5bfc\u5165\u8fc7\u7a0b\u53ef\u80fd\u4f1a\u82b1\u8d39\u4e00\u4e9b\u65f6\u95f4\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u6570\u636e\u91cf\u548c\u7cfb\u7edf\u6027\u80fd\u3002\u5bfc\u5165\u5b8c\u6210\u540e\uff0c\u6570\u636e\u5c06\u53ef\u7528\u4e8e MySQL \u6570\u636e\u5e93\u4e2d\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u628a\u6570\u636e\u5e93\u5bfc\u5165\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\u6570\u636e\u5e93\u5230 mysql \u5206\u4e94\u6b65\u5b8c\u6210\uff1a\u521b\u5efa\u6570\u636e\u5e93\u51c6\u5907\u6570\u636e\u6e90\u4f7f\u7528 load data infile \u547d\u4ee4\u8bbe\u7f6e\u5bfc\u5165\u9009\u9879\uff08\u53ef\u9009\uff09\u6267\u884c\u5bfc\u5165 \u5982\u4f55\u5c06\u6570\u636e\u5e93\u5bfc\u5165 MySQL \u5bfc\u5165\u6570\u636e\u5e93\u5230 MySQL \u662f\u4e00\u4e2a\u5c06\u5916\u90e8\u6570\u636e\u6e90\u7684\u6570\u636e\u79fb\u52a8\u5230 MySQL \u6570\u636e\u5e93\u7684\u8fc7\u7a0b\u3002\u4ee5\u4e0b\u662f\u5bfc\u5165\u6570\u636e\u5e93\u5230 MySQL \u7684\u5206\u6b65\u6307\u5357\uff1a 1. \u521b\u5efa\u6570\u636e\u5e93 \u5728\u5bfc\u5165\u6570\u636e\u4e4b\u524d\uff0c\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u8981\u63a5\u6536\u6570\u636e\u7684\u6570\u636e\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5728 MySQL \u4e2d\u521b\u5efa\u6570\u636e\u5e93\uff1a CREATE DATABASE database_name; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d database_name \u662f\u8981\u521b\u5efa\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002 2. \u51c6\u5907\u6570\u636e\u6e90 \u5c06\u6570\u636e\u5bfc\u5165 MySQL \u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u6570\u636e\u6e90\u4ee5\u53ef\u4f9b MySQL \u8bc6\u522b\u7684\u683c\u5f0f\u5b58\u5728\u3002\u8fd9\u901a\u5e38\u6d89\u53ca\u5c06\u6e90\u6570\u636e\u5bfc\u51fa\u4e3a SQL \u517c\u5bb9\u7684\u683c\u5f0f\uff0c\u4f8b\u5982 CSV\u3001SQL \u8f6c\u50a8\u6216 XML\u3002 3. \u4f7f\u7528 MySQL \u5bfc\u5165\u547d\u4ee4 MySQL \u4e2d\u63d0\u4f9b\u4e86\u51e0\u4e2a\u547d\u4ee4\u7528\u4e8e\u5bfc\u5165\u6570\u636e\uff0c\u6700\u5e38\u7528\u7684\u547d\u4ee4\u662f LOAD DATA INFILE\uff1a LOAD DATA INFILE &#8216;file_path&#8217; INTO TABLE [&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-6450","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6450","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=6450"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6450\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}