{"id":1006,"date":"2017-10-28T14:46:40","date_gmt":"2017-10-28T06:46:40","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=1006"},"modified":"2017-10-28T14:46:40","modified_gmt":"2017-10-28T06:46:40","slug":"mysql5-7-select-into-%e7%9a%84%e8%af%ad%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=1006","title":{"rendered":"MYSQL5.7 select &#8230; into \u7684\u8bed\u6cd5"},"content":{"rendered":"<p>select&#8230;into \u7684\u8bed\u6cd5\u5141\u8bb8\u67e5\u5bfb\u7ed3\u679c\u5b58\u5230\u4e00\u4e2a\u53d8\u91cf\u6216\u5199\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff1a<\/p>\n<ul>\n<li>SELECT &#8230; INTO <em><strong>var_list<\/strong><\/em>\uff1a\u9009\u62e9\u5217\u7684\u503c\u5e76\u628a\u5b83\u4eec\u5b58\u5230\u53d8\u91cf\u4e2d\u53bb\u3002<\/li>\n<li>SELECT &#8230; INTO OUTFILE\uff1a\u5c06\u9009\u5b9a\u7684\u5217\u5199\u5230\u5916\u90e8\u6587\u4ef6\u4e2d\u3002\u5217\u548c\u884c\u7684\u7ed3\u675f\u7b26\u53ef\u4ee5\u6307\u5b9a\u3002<\/li>\n<li>SELECT &#8230; INTO DUMPFILE\uff1a\u4ea4\u4e00\u884c\u5199\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5b83\u4e0d\u5305\u542b\u4efb\u4f55\u683c\u5f0f\u3002<\/li>\n<\/ul>\n<p>INTO\u5b50\u53e5\u4e0d\u8981\u7528\u4e8e\u5d4c\u5957\u7684SELECT\u4e2d\uff0c\u56e0\u4e3a\u6bcf\u4e00\u4e2aSELECT\u5fc5\u987b\u8fd4\u56de\u5b83\u7684\u7ed3\u679c\u5230\u5b83\u7684\u5916\u5c42SELECT\u4e2d\u3002<\/p>\n<p>INTO\u5b50\u53e5\u80fd\u547d\u540d\u4e00\u4e2a\u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u53d8\u91cf\u7684\u53d8\u91cf\u5217\u8868\uff0c\u5b83\u80fd\u662f\u4e00\u4e2a\u7528\u6237\u5b9a\u4e49\u7684\u53d8\u91cf\uff0c\u4e00\u4e2a\u5b58\u50a8\u8fc7\u7a0b\uff0c\u4e00\u4e2a\u51fd\u6570\u7684\u53c2\u6570\u6216\u672c\u5730\u5b58\u50a8\u7a0b\u5e8f\u7684\u672c\u5730\u53d8\u91cf\u3002\uff08\u5728\u51c6\u5907\u9636\u6bb5\u7684SELECT &#8230; INTO OUTFILE\uff0c\u53ea\u80fd\u4f7f\u7528\u7528\u6237\u5b9a\u4e49\u53d8\u91cf\uff1bsee <a class=\"xref\" title=\"13.6.4.2\u00a0Local Variable Scope and Resolution\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/local-variable-scope.html\">Section\u00a013.6.4.2, \u201cLocal Variable Scope and Resolution\u201d<\/a>.\uff09<\/p>\n<p>\u88ab\u9009\u62e9\u7684\u503c\u88ab\u5206\u914d\u5230\u53d8\u91cf\u4e2d\u3002\u53d8\u91cf\u7684\u6570\u91cf\u5fc5\u987b\u548c\u5217\u7684\u6570\u91cf\u76f8\u5339\u914d\u3002\u67e5\u8be2\u5e94\u8be5\u53ea\u8fd4\u56de\u4e00\u884c\u8bb0\u5f55\u3002\u5982\u679c\u67e5\u8be2\u6ca1\u6709\u8fd4\u56de\u4efb\u4f55\u884c\uff0c\u4f1a\u8fd4\u56de\u4e00\u4e2a\u9519\u8bef\u4ee3\u7801\u4e3a1329\u7684\u8b66\u544a\uff08\u65e0\u6570\u636e\uff09\uff0c\u5e76\u4e14\u53d8\u91cf\u503c\u4fdd\u6301\u4e0d\u53d8\u3002\u5982\u679c\u67e5\u8be2\u8fd4\u56de\u591a\u884c\u8bb0\u5f55\uff0c\u4f1a\u4ea7\u751f\u4e00\u4e2a1172\u7684\u9519\u8bef\uff08\u7ed3\u679c\u7531\u591a\u884c\u7ec4\u6210\uff09\u3002\u5982\u679c\u4ea7\u751f\u591a\u884c\u8bb0\u5f55\u53ef\u4ee5\uff0c\u53ef\u4ee5\u4f7f\u7528LIMIT 1\u53bb\u9650\u5236\u7ed3\u679c\u53ea\u4e3a\u4e00\u884c\u3002<\/p>\n<pre>select building,room_number,capactity into @x, @y, @z from classroom limit 1<\/pre>\n<p>\u7528\u6237\u5b9a\u7684\u53d8\u91cf\u662f\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u7684\u3002\uff08See <a class=\"xref\" title=\"9.4\u00a0User-Defined Variables\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/user-variables.html\">Section\u00a09.4, \u201cUser-Defined Variables\u201d<\/a>. \uff09<\/p>\n<p>SELECT &#8230; INTO OUTFILE &#8216;<em><strong>file_name<\/strong><\/em>&#8216;\u5f62\u5f0f\u7684SELECT\u8bed\u53e5\u5c06\u9009\u62e9\u7684\u884c\u5199\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\u3002\u8fd9\u4e2a\u6587\u4ef6\u88ab\u521b\u5efa\u5728\u670d\u52a1\u5668\u4e3b\u673a\u4e0a\uff0c\u6240\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u8bed\u53e5\u7684\u7528\u6237\u5fc5\u987b\u8981\u6709<strong>FILE<\/strong>\u6743\u9650\u624d\u884c\u3002<em><strong>file_name<\/strong><\/em>\u4e0d\u80fd\u662f\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684\u6587\u4ef6\uff0c\u9632\u6b62\u90a3\u4e9b\u5b58\u5728\u7684\u6587\u4ef6\u88ab\u9500\u6bc1\u3002character-set-filesystem\u7cfb\u7edf\u53d8\u91cf\u63a7\u5236\u7740\u6587\u4ef6\u540d\u7684\u89e3\u91ca\u3002<\/p>\n<p>SELECT &#8230; INTO OUTFILE\u8bed\u53e5\u4e3b\u8981\u7528\u4e8e\u5feb\u901f\u7684dump\u4e00\u4e2a\u8868\u5230\u670d\u52a1\u5668\u4e0a\u7684\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\u4e2d\u3002\u5982\u679c\u4f60\u60f3\u5c06\u7ed3\u679c\u6587\u4ef6\u521b\u5efa\u5230\u5176\u5b83\u670d\u52a1\u5668\u4e0a\uff0c\u800c\u4e0d\u662f \u672c\u5730\u670d\u52a1\u5668\uff0c\u90a3\u4e48\u4e0d\u80fd\u4f7f\u7528SELECT &#8230; INTO OUTFILE\u8bed\u53e5\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u529e\u6cd5\u5199\u5230\u4e00\u4e2a\u76f8\u5bf9\u7684\u670d\u52a1\u5668\u8def\u5f84\u4e0a\u3002<\/p>\n<p>\u4f46\u662f\u5982\u679c\u8fdc\u7a0b\u670d\u52a1\u5668\u5b89\u88c5\u4e86MYSQL \u5ba2\u6237\u7aef \uff0c\u53ef\u4ee5\u4f7f\u7528\u5ba2\u6237\u7aef\u547d\u4ee4\u4ee3\u66ff\u5982\uff1a<code>mysql -e \"SELECT ...\" &gt; <strong><em>file_name<\/em><\/strong><\/code>\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u5ba2\u6237\u4e3b\u673a\u4e0a\u4ea7\u751f\u4e00\u4e2a\u6587\u4ef6\u3002<\/p>\n<p>\u5b83\u540c\u6837\u4e5f\u80fd\u5c06\u7ed3\u679c\u521b\u5efa\u5728\u4e0d\u540c\u7684\u4e3b\u673a\u4e0a\uff0c\u5982\u679c\u8fdc\u7a0b\u4e3b\u673a\u7684\u6587\u4ef6\u5730\u5740\u53ef\u4ee5\u4f7f\u7528\u7f51\u7edc\u6620\u5c04\u8def\u5230\u670d\u52a1\u5668\u4e0a\uff0c\u5e76\u4e14\u6709\u6743\u9650\u88ab\u8bbf\u95ee\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0bmysql\uff08\u6216\u67d0\u79cd\u5ba2\u6237\u7aef\u7a0b\u5e8f\uff09\u4e0d\u9700\u8981\u5b89\u88c5\u5230\u76ee\u6807\u4e3b\u673a\u4e0a\u3002<\/p>\n<p>SELECT &#8230; INTO OUTFILE\u662fLOAD DATA INFILE\u7684\u4e00\u4e2a\u7ec4\u4ef6\u3002\u8f93\u51fa\u7684\u5217\u503c\u7684\u5b57\u7b26\u96c6\u88abCHARACTER SET\u5b50\u53e5\u6307\u5b9a\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u8be5\u5b50\u53e5\uff0c\u8f93\u51fa\u7684\u9ed8\u8ba4\u5b57\u7b26\u96c6\u662fbinary character set\u3002\u5b9e\u9645\u4e0a\uff0c\u6ca1\u6709\u5b57\u7b26\u96c6\u88ab\u8f6c\u6362\u3002\u5982\u679c\u7ed3\u679c\u96c6\u5305\u542b\u7684\u5217\u6709\u51e0\u79cd\u5b57\u7b26\u96c6\uff0c\u90a3\u4e48\u4e5f\u53ef\u4ee5\u5f88\u597d\u7684\u8f93\u51fa\uff0c\u4e0d\u8fc7\u4f60\u53ef\u80fd\u4e0d\u80fd\u6b63\u786e\u7684\u5bfc\u5165\u3002<\/p>\n<p>export_options\u4e2d\u7684FIELDS\u548cLINES\u5b50\u53e5\u7528\u4e8eLOAD DATA INFILE\u8bed\u53e5\u3002\uff08See <a class=\"xref\" title=\"13.2.6\u00a0LOAD DATA INFILE Syntax\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/load-data.html\">Section\u00a013.2.6, \u201cLOAD DATA INFILE Syntax\u201d<\/a>\uff09<\/p>\n<p>\u6ce8\u610f\uff1a\u7531INTO OUTFILE\u6216INTO DUMPFILE\u521b\u5efa\u7684\u6587\u4ef6\u662f\u6240\u6709\u7528\u6237\u90fd\u53ef\u4ee5\u5199\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>select&#8230;into \u7684\u8bed\u6cd5\u5141\u8bb8\u67e5\u5bfb\u7ed3\u679c\u5b58\u5230\u4e00\u4e2a\u53d8\u91cf\u6216\u5199\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff1a SELECT &#8230; INTO var_list\uff1a\u9009\u62e9\u5217\u7684\u503c\u5e76\u628a\u5b83&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=1006\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"class_list":["post-1006","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/1006","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1006"}],"version-history":[{"count":5,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/1006\/revisions"}],"predecessor-version":[{"id":1011,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/1006\/revisions\/1011"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}