自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

MySQL查詢結(jié)果導(dǎo)出到文件的另類方法

數(shù)據(jù)庫(kù) MySQL
一般大家都會(huì)用 “SELECT INTO OUTFIL”將查詢結(jié)果導(dǎo)出到文件,但是這種方法不能覆蓋或者添加到已經(jīng)創(chuàng)建的文件,下文為您介紹的這種方法則很好地解決了此問(wèn)題。

MySQL查詢結(jié)果導(dǎo)出到文件的方法很多人都會(huì),一般大家都會(huì)用 “SELECT INTO OUTFIL”將查詢結(jié)果導(dǎo)出到文件,但是這種MySQL查詢結(jié)果導(dǎo)出到文件方法不能覆蓋或者添加到已經(jīng)創(chuàng)建的文件。例如:

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

 還可以使用另外一種方法:

  1. mysql> pager cat > /tmp/t1.txt  
  2. PAGER set to 'cat > /tmp/t1.txt'  
  3. mysql> select 1;\! cat /tmp/t1.txt  
  4. 1 row in set (0.00 sec)  
  5. +---+  
  6. | 1 |  
  7. +---+  
  8. | 1 |   
  9. +---+  

這樣你能很方便的查詢到2條sql的差異:

  1. mysql> pager cat > /tmp/t01.txt  
  2. PAGER set to 'cat > /tmp/t01.txt'  
  3. mysql> select 12345 union select 67890;  
  4. 2 rows in set (0.02 sec)  
  5. mysql> pager cat > /tmp/t02.txt  
  6. PAGER set to 'cat > /tmp/t02.txt'  
  7. mysql> select 12345 union select 67891;  
  8. 2 rows in set (0.00 sec)  
  9. mysql> \! vimdiff -o  /tmp/t0[12].txt  
  10. 2 files to edit  
  11.   +-------+  
  12.   | 12345 |  
  13.   +-------+  
  14.   | 12345 |  
  15.   | 67890 |                                                                                                                   
  16.   +-------+                                                                                                                
  17. /tmp/t01.txt   
  18.   +-------+  
  19.   | 12345 |  
  20.   +-------+  
  21.   | 12345 |  
  22.   | 67891 |                                                                                                                   
  23.   +------+                                                                                                           
  24. /tmp/t02.txt  

 

 

 

 

【編輯推薦】

MySQL查詢結(jié)果條數(shù)編號(hào)示例

MySQL查詢分頁(yè)的優(yōu)化

MySQL查詢結(jié)果按某值排序

使用函數(shù)實(shí)現(xiàn)MySQL查詢行號(hào)

MySQL查詢中的非空問(wèn)題

責(zé)任編輯:段燃 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-05-16 13:05:56

SQL導(dǎo)入導(dǎo)出MYSQL

2010-10-15 11:05:31

MYSQL查詢結(jié)果

2022-11-07 12:22:00

2009-04-14 09:24:40

OracleXML導(dǎo)出

2009-09-17 08:47:00

Linq查詢

2010-11-23 11:16:35

MySQL表別名

2025-04-10 07:30:43

2010-11-25 14:45:19

MySQL查詢結(jié)果

2009-11-04 09:05:30

Windows 7jumplist

2010-10-27 14:34:56

Oracle日志文件

2010-11-25 15:36:09

MySQL查詢結(jié)果集

2010-10-14 15:07:44

MySQL慢查詢

2010-11-25 14:05:15

MySQL查詢中間記錄

2010-11-25 14:52:35

MySQL隨機(jī)查詢

2010-11-25 13:56:30

MySQL查詢結(jié)果

2010-11-09 14:29:50

SQL SERVER查

2014-05-08 11:21:22

Linux應(yīng)用程序排查故障

2010-10-13 17:22:12

MySQL查詢亂碼

2010-10-14 09:15:20

MySQL查詢

2010-11-25 15:43:02

MYSQL查詢重復(fù)記錄
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)