MySQL查询结果导出到文件的另类方法

WBOY
풀어 주다: 2016-06-07 14:51:47
원래의
1431명이 탐색했습니다.

MySQL查询结果导出到文件的方法很多人都会,一般大家都会用 SELECT INTO OUTFIL将查询结果导出到文件,但是这种MySQL查询结果导出到文件方法不能覆盖或者添加到已经创建的文件。例如: mysqlselect1intooutfile'/tmp/t1.txt'; QueryOK,1rowaffected(0.00sec)

  MySQL查询结果导出到文件的方法很多人都会,一般大家都会用 “SELECT INTO OUTFIL”将查询结果导出到文件,但是这种MySQL查询结果导出到文件方法不能覆盖或者添加到已经创建的文件。例如:

  mysql> select 1 into outfile '/tmp/t1.txt';  
  Query OK, 1 row affected (0.00 sec)  
  mysql> select 1 into outfile '/tmp/t1.txt';  
  ERROR 1086 (HY000): File '/tmp/t1.txt' already exists  

  还可以使用另外一种方法:

  mysql> pager cat > /tmp/t1.txt  
  PAGER set to 'cat > /tmp/t1.txt'  
  mysql> select 1;\! cat /tmp/t1.txt  
  1 row in set (0.00 sec)  
  +---+  
  | 1 |  
  +---+  
  | 1 |   
  +---+  

  这样你能很方便的查询到2条sql的差异:

  mysql> pager cat > /tmp/t01.txt  
  PAGER set to 'cat > /tmp/t01.txt'  
  mysql> select 12345 union select 67890;  
  2 rows in set (0.02 sec)  
  mysql> pager cat > /tmp/t02.txt  
  PAGER set to 'cat > /tmp/t02.txt'  
  mysql> select 12345 union select 67891;  
  2 rows in set (0.00 sec)  
  mysql> \! vimdiff -o  /tmp/t0[12].txt  
  2 files to edit  
    +-------+  
    | 12345 |  
    +-------+  
    | 12345 |  
    | 67890 |                                                                                                                   
    +-------+                                                                                                                
  /tmp/t01.txt   
    +-------+  
    | 12345 |  
    +-------+  
    | 12345 |  
    | 67891 |                                                                                                                   
    +------+                                                                                                           
  /tmp/t02.txt  

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!