{"id":25,"date":"2021-07-02T17:18:59","date_gmt":"2021-07-02T09:18:59","guid":{"rendered":"http:\/\/szx622.top\/?p=25"},"modified":"2021-07-05T11:52:13","modified_gmt":"2021-07-05T03:52:13","slug":"%e4%bd%bf%e7%94%a8mysqlimport%e8%bf%9b%e8%a1%8c%e7%ba%af%e6%96%87%e6%9c%ac%e6%95%b0%e6%8d%ae%e5%af%bc%e5%85%a5","status":"publish","type":"post","link":"https:\/\/szx622.top\/?p=25","title":{"rendered":"\u4f7f\u7528mysqlimport\u8fdb\u884c\u7eaf\u6587\u672c\u6570\u636e\u5bfc\u5165"},"content":{"rendered":"\n<p><code>mysqlimport<\/code> \u662f\u4e00\u4e2a\u5c06\u4ee5\u7279\u5b9a\u683c\u5f0f\u5b58\u653e\u7684\u7eaf\u6587\u672c\u6570\u636e\u5bfc\u5165\u5230\u6307\u5b9a\u7684MySQL Server \u4e2d\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u6bd4\u5982\u5c06\u4e00\u4e2a\u6807\u51c6\u7684csv \u6587\u4ef6\u5bfc\u5165\u5230\u67d0\u6307\u5b9a\u6570\u636e\u5e93\u7684\u6307\u5b9a\u8868\u4e2d\u3002mysqlimport \u5de5\u5177\u5b9e\u9645\u4e0a\u4e5f\u53ea\u662f\u201c<strong>load data infile<\/strong>\u201d\u547d\u4ee4\u7684\u4e00\u4e2a\u5305\u88c5\u5b9e\u73b0\u3002\u5728\u5bfc\u5165\u5927\u578b\u6570\u636e\u7684\u65f6\u5019\uff0c\u6548\u7387\u8fd8\u662f\u5f88\u9ad8\u7684\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">1\u3001mysqlimport\u57fa\u672c\u8bed\u6cd5<\/h1>\n\n\n\n<pre class=\"wp-block-preformatted\">mysqlimport [options] db_name textfile1 [textfile2 ...]         #\u6587\u4ef6\u53ef\u4ee5\u8ddf\u591a\u4e2a\uff0c\u5927\u90e8\u5206\u60c5\u51b5\u9700\u5c3d\u91cf\u6307\u5b9a\u7edd\u5bf9\u8def\u5f84\uff0c\u8be5\u547d\u4ee4\u4f1a\u6839\u636e\u6587\u4ef6\u540d\uff08\u65e0\u89c6\u6587\u4ef6\u540e\u7f00\u540d\uff09\u5bfc\u5165\u5230\u5bf9\u5e94\u7684\u8868\u4e2d<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">2\u3001mysqlimport\u5e38\u7528\u9009\u9879<\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u9009\u9879<\/th><th>\u91ca\u4e49<\/th><\/tr><\/thead><tbody><tr><td>-l, &#8211;lock-tables<\/td><td>\u5199\u5165\u65f6\u9501\u5b9a\u6240\u6709\u8868<\/td><\/tr><tr><td>-u, &#8211;user=name<\/td><td>\u6307\u5b9a\u767b\u5165MySQL\u7528\u6237\u540d<\/td><\/tr><tr><td>-p, &#8211;password[=name]<\/td><td>\u6307\u5b9a\u7528\u6237\u5bc6\u7801\uff0c\u4f7f\u7528-p\u65f6\u5bc6\u7801\u4e0e-p\u4e4b\u95f4\u4e0d\u5141\u8bb8\u6709\u7a7a\u683c<\/td><\/tr><tr><td>-h, &#8211;host=name<\/td><td>\u6307\u5b9a\u8fdc\u7a0b\u8fde\u63a5\u7684\u670d\u52a1\u5668<\/td><\/tr><tr><td>-P,&#8211;port=#<\/td><td>\u6307\u5b9a\u8fdc\u7a0b\u670d\u52a1\u5668\u6240\u7528\u7684\u6570\u636e\u5e93\u77ed\u88e4<\/td><\/tr><tr><td>-f, &#8211;force<\/td><td>\u5728\u5bfc\u5165\u67d0\u4e2a\u6570\u636e\u6587\u4ef6\u51fa\u9519\u65f6\uff0c\u8df3\u8fc7\u8be5\u6587\u4ef6\uff0c\u7ee7\u7eed\u5bfc\u5165\u5176\u4ed6\u6570\u636e\u6587\u4ef6\uff1b\u5e76\u4e0d\u4f1a\u8df3\u8fc7\u5355\u4e2a\u6587\u4ef6\u4e2d\u7684\u67d0\u6761\u9519\u8bef\u6570\u636e<\/td><\/tr><tr><td>-i, &#8211;ignore<\/td><td>\u5728\u5bfc\u5165\u7684\u6570\u636e\u4e0e\u552f\u4e00\u952e\u6216\u4e3b\u952e\u51b2\u7a81\u65f6\uff0c\u4f1a\u5ffd\u7565\u8be5\u6761\u6570\u636e\uff1b\u5728\u6570\u636e\u683c\u5f0f\u6709\u8bef\u65f6\uff0c\u4e5f\u4f1a\u5ffd\u7565\u9519\u8bef\u5f3a\u5236\u63d2\u5165<\/td><\/tr><tr><td>-r, &#8211;replace<\/td><td>\u5728\u5bfc\u5165\u7684\u6570\u636e\u4e0e\u552f\u4e00\u952e\u6216\u4e3b\u952e\u51b2\u7a81\u65f6\uff0c\u4f1a\u66ff\u6362\u6389\u539f\u6570\u636e<\/td><\/tr><tr><td>-d, &#8211;delete<\/td><td>\u5bfc\u5165\u524d\uff0c\u5148\u6e05\u7a7a\u88ab\u5bfc\u5165\u6570\u636e\u7684\u8868<\/td><\/tr><tr><td>-c, &#8211;columns=name<\/td><td>\u5f80\u8868\u91cc\u7684\u6307\u5b9a\u5b57\u6bb5\u5bfc\u5165\u6570\u636e\uff0c\u5982\uff1a&#8211;columns=&#8217;Name,Age,Gender&#8217;<\/td><\/tr><tr><td>&#8211;ignore-lines=#<\/td><td>\u5ffd\u7565\u6587\u672c\u7684\u524d\u51e0\u884c<\/td><\/tr><tr><td>-L, &#8211;local<\/td><td>\u5168\u90e8\u4ece\u5ba2\u6237\u7aef\u8bfb\u53d6\u6570\u636e<\/td><\/tr><tr><td>&#8211;fields-enclosed-by=<\/td><td>\u6307\u5b9a\u6587\u672c\u6587\u4ef6\u4e2d\u6570\u636e\u7684\u8bb0\u5f55\u65f6\u4ee5\u4ec0\u4e48\u62ec\u8d77\u7684\uff0c\u5f88\u591a\u60c5\u51b5\u4e0b\u6570\u636e\u4ee5\u53cc\u5f15\u53f7\u62ec\u8d77\u3002 \u9ed8\u8ba4\u7684\u60c5\u51b5\u4e0b\u6570\u636e\u662f\u6ca1\u6709\u88ab\u5b57\u7b26\u62ec\u8d77\u7684<\/td><\/tr><tr><td>&#8211;fields-terminated-by=<\/td><td>\u6307\u5b9a\u5404\u4e2a\u6570\u636e\u7684\u503c\u4e4b\u95f4\u7684\u5206\u9694\u7b26\uff0c\u5728\u53e5\u53f7\u5206\u9694\u7684\u6587\u4ef6\u4e2d\uff0c \u5206\u9694\u7b26\u662f\u53e5\u53f7\u3002\u9ed8\u8ba4\u7684\u5206\u9694\u7b26\u662f\u8df3\u683c\u7b26\uff08Tab\uff09<\/td><\/tr><tr><td>&#8211;lines-terminated-by=<\/td><td>\u6307\u5b9a\u884c\u5206\u9694\u7b26\uff1b\u9ed8\u8ba4\u662f\u6587\u672c\u4e2d\u7684\u6362\u884c\u7b26<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">3\u3001\u4f7f\u7528\u6ce8\u610f\u4e8b\u9879<\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>\u9700\u5bf9mysql\u670d\u52a1\u7684\u5168\u5c40\u53d8\u91cf <code>secure_file_priv<\/code> \u8fdb\u884c\u8bbe\u7f6e\uff1a<ul><li>\u5982\u679c\u8bbe\u7f6e\u4e3a\u7a7a\uff0c\u5219\u8be5\u53d8\u91cf\u65e0\u6548\u3002<\/li><li>\u5982\u679c\u8bbe\u7f6e\u4e3a\u76ee\u5f55\u7684\u540d\u79f0\uff0c\u670d\u52a1\u5668\u4f1a\u5c06\u5bfc\u5165\u548c\u5bfc\u51fa\u64cd\u4f5c\u9650\u5236\u4e3a\u4ec5\u5904\u7406\u8be5\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u3002\u76ee\u5f55\u5fc5\u987b\u5b58\u5728\uff1b\u670d\u52a1\u5668\u4e0d\u4f1a\u521b\u5efa\u5b83\u3002<\/li><li>\u5982\u679c\u8bbe\u7f6e\u4e3a<code>NULL<\/code>\uff0c\u670d\u52a1\u5668\u5c06\u7981\u7528\u5bfc\u5165\u548c\u5bfc\u51fa\u64cd\u4f5c\u3002<\/li><\/ul><\/li><li>\u5982\u679c\u6587\u672c\u4e2d\u7684\u67d0\u4e00\u6761\u6570\u636e\u548c\u8868\u7ed3\u6784\u4e0d\u5339\u914d\uff0c\u8be5\u547d\u4ee4\u4f1a\u56de\u6eda\uff0c\u4e0d\u4f1a\u5bf9\u8be5\u6587\u672c\u8fdb\u884c\u4efb\u4f55\u64cd\u4f5c\uff0c\u5373\u5176\u4ed6\u6570\u636e\u4e5f\u4e0d\u4f1a\u5bfc\u5165\u3002\u6682\u672a\u627e\u5230\u5408\u9002\u7684\u89e3\u51b3\u65b9\u6cd5\uff0c\u53ef\u80fd\u9700\u8981\u5728\u5bfc\u5165\u524d\u786e\u8ba4\u6570\u636e\u683c\u5f0f\u3002<\/li><li><code>local<\/code> \u9009\u9879\u4e0d\u53ef\u7528\uff0c\u8bf4\u662f\u6211\u7684\u7248\u672c\u4e0d\u652f\u6301\uff08mysql\u7248\u672c\u4e3a8.0.16\uff09\uff0c\u5728\u4f7f\u7528 <code>load data infile<\/code> \u65f6\uff0c\u8fd9\u4e2a\u9009\u9879\u4e5f\u4e0d\u80fd\u7528\u3002<\/li><li>\u8fd8\u6709\u8bb8\u591a\u5173\u4e8essl\u7684\u8fde\u63a5\u65b9\u5f0f\uff0c\u8fd9\u91cc\u4e0d\u505a\u9610\u8ff0<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4f7f\u7528mysql\u5bfc\u5165\u672c\u5730\u6587\u4ef6\u6587\u4ef6\u65f6\u63d0\u793a&#8221;ERROR 1148 (42000): The used command is not allowed with this MySQL version&#8221;<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\r\n  - \u89e3\u51b3\u529e\u6cd5\u5982\u4e0b\uff1a\r\n  \r\n  - \u670d\u52a1\u5668\u7aef\uff1a\u9700\u8981\u5c06local_infile\u8fd9\u4e2a\u5168\u5c40\u53d8\u91cf\u8bbe\u7f6e\u4e3aON\uff0c\u767b\u9646\u5230MYSQL\u4e2d\u540e\u6267\u884c\u547d\u4ee4\r\n  - \u663e\u793a\u5f53\u524dlocal_infile\u503c\u4e3aOFF\uff0c\u6ca1\u6709\u4ece\u672c\u5730\u8f7d\u5165\u6587\u4ef6\u6743\u9650 \r\n  - \u6267\u884c\u547d\u4ee4\u5c06\u5176\u503c\u6539\u4e3aON \r\n  - set  global local_infile = 'on' ;\r\n  - \u6539\u5b8c\u540e\u91cd\u65b0\u6267\u884c\u547d\u4ee4\u53d1\u73b0\u8fd8\u662f\u4f1a\u63d0\u793a\u9519\u8bef\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u5728\u5ba2\u6237\u7aef\u542f\u52a8\u7684\u65f6\u5019\u6dfb\u52a0\u53c2\u6570 \r\n  - \u5ba2\u6237\u7aef\u542f\u52a8\u65f6\u52a0\u4e0a--local-infile=1\u7684\u53c2\u6570\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a \r\n  - mysql  -h ip -p3306 -u root -p --local-infile=1  -s \u8def\u5f84 \/mysql\/mysql.sock\r\n  - \u8bbe\u7f6e\u5b8c\u6210\u540e\u5373\u53ef\u4ece\u672c\u5730\u8f7d\u5165\u6587\u4ef6\u4e86\r\n\r<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysqlimport \u662f\u4e00\u4e2a\u5c06\u4ee5\u7279\u5b9a\u683c\u5f0f\u5b58\u653e\u7684\u7eaf\u6587\u672c\u6570\u636e\u5bfc\u5165\u5230\u6307\u5b9a\u7684MySQL Server \u4e2d\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u6bd4\u5982\u5c06\u4e00\u4e2a\u6807\u51c6\u7684csv \u6587\u4ef6\u5bfc\u5165\u5230\u67d0\u6307\u5b9a\u6570\u636e\u5e93\u7684\u6307\u5b9a\u8868\u4e2d\u3002mysqlimport \u5de5\u5177\u5b9e\u9645\u4e0a\u4e5f\u53ea\u662f\u201cload data infile\u201d\u547d\u4ee4\u7684\u4e00\u4e2a\u5305\u88c5\u5b9e\u73b0\u3002\u5728\u5bfc\u5165\u5927\u578b\u6570\u636e\u7684\u65f6\u5019\uff0c\u6548\u7387\u8fd8\u662f\u5f88\u9ad8\u7684\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[6,8,7],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-2","tag-mysql","tag-8","tag-7"],"_links":{"self":[{"href":"https:\/\/szx622.top\/index.php?rest_route=\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/szx622.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/szx622.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/szx622.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/szx622.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25"}],"version-history":[{"count":4,"href":"https:\/\/szx622.top\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":34,"href":"https:\/\/szx622.top\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions\/34"}],"wp:attachment":[{"href":"https:\/\/szx622.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/szx622.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/szx622.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}