隨筆-159  評論-114  文章-7  trackbacks-0

          一般大家都會用 “SELECT INTO OUTFIL”將查詢結果導出到文件,但是這種方法不能覆蓋或者添加到已經創建的文件。例如:

          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


          posted on 2009-09-29 15:43 北國狼人的BloG 閱讀(2551) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 嘉荫县| 郴州市| 沅江市| 余江县| 和林格尔县| 连城县| 裕民县| 隆德县| 深圳市| 新乐市| 汉沽区| 衢州市| 靖宇县| 平顺县| 德令哈市| 抚宁县| 甘泉县| 札达县| 乌鲁木齐县| 安吉县| 公主岭市| 英吉沙县| 修文县| 翁牛特旗| 弥勒县| 吉水县| 罗城| 罗山县| 墨脱县| 阿拉善右旗| 忻州市| 武平县| 武胜县| 西藏| 清徐县| 新建县| 临沭县| 乌鲁木齐县| 慈溪市| 新蔡县| 开封市|