mysql 導出數據到txt文件

示例:


 SELECT email FROM xxxxxx where email is not null and email <> ''  into  outfile '/mail.txt' lines terminated by '\r\n' ;


SELECT email FROM u_emails where email is not null and email <>'' and email like '%@163.com%' LIMIT 0 ,10 into outfile '/163.txt' lines terminated by ';\r\n';


SELECT email FROM u_emails where email is not null and email <>'' and email not like '%@163.com%' and email not like '%@sina.com%' and email not like '%@qq.com%' LIMIT 0 ,10 into outfile '/other.txt' lines terminated by ';\r\n';

 

說明:


1.導出文件目錄:


修改輸出文件名的目錄,以便放在指定的位置。如'a.txt'可以改成'./a.txt'或'/a.txt'。

其中'./a.txt'放在c:\mysql\data目錄下了,

而'/a.txt'文件則放在c:\目錄下了。


select命令認爲的當前目錄是數據庫的存放目錄


 


2.導出數據格式 


字段之間的分隔字符,轉義字符,包括字符,及記錄行分隔字符。列在下面: 

FIELDS

TERMINATED BY '\t'

[OPTIONALLY] ENCLOSED BY ''

ESCAPED BY '\\' 

LINES 

TERMINATED BY '\n'


TERMINATED 表示字段分隔 

[OPTIONALLY] ENCLOSED 表示字段用什麼字符包括起來,

如果使用了OPTIONALLY則只有CHAR和VERCHAR被包括 ESCAPED 表示當需要轉義時用什麼作爲轉義字符 

LINES TERMINATED 表示每行記錄之間用什麼分隔


http://www.cnblogs.com/xh831213/archive/2012/04/10/2439886.html


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章