mysql匯出查詢結果到csv方法

2021-10-10 16:37:43 字數 996 閱讀 1006

我們可以使用 into outfile, fields terminated by, optionally enclosed by, line terminated by語句實現匯出csv 

into outfile 『匯出的目錄和檔名』 

指定匯出的目錄和檔名

fields terminated by 『欄位間分隔符』 

定義欄位間的分隔符

optionally enclosed by 『字段包圍符』 

定義包圍欄位的字元(數值型字段無效)

lines terminated by 『行間分隔符』 

定義每行的分隔符 

select ts.realname, tsq.questionid,tsq.useranswer,tsq.solvetime,tsq.seequescount,tsq.score,tsq.sort  from t_teststudentquestion tsq,t_teststudent tts,t_classinfostudent tcs ,t_test tt,t_student ts

where tcs.classinfoid = 'fa4c211551332471015137db66da0034'

and tcs.studentid = tts.studentid

and tts.id = tsq.teststudentid

and tts.testid = tt.id

and tt.subject= '英語'

and ts.id = tts.studentid

and tt.testtypeid = 'testtype001'

and tt.way = 0

into outfile 'd:\\table.csv' fields terminated by ',' optionally enclosed by '"' lines terminated by '\r\n';

在windows環境注意,檔案的路徑要使用"\\"

MYSQL匯出查詢結果到檔案

select order id product name qty from orders into outfile data data.txt select order id product name qty from orders into outfile tmp orders.csv field...

mysql匯出查詢結果到文件

其實挺簡單,就乙個命令 select from my table into outfile tmp abc.xls 然後就是ftp把檔案弄回本地了。我的是程式自動放到c 下 另外,還有一種匯出的方式,相較於上者而言,這種可以對已經存在的檔案直接覆蓋。使用outfile的方法 mysql select...

將mysql的查詢結果匯出為csv

要將mysql的查詢結果匯出為csv,一般會使用php連線mysql執行查詢,將返回的查詢結果使用php生成csv格式再匯出。但這樣比較麻煩,需要伺服器安裝php才可以實現。我們可以使用 into outfile,fields terminated by,optionally enclosed by...