mysql實(shí)現(xiàn)查詢結(jié)果導(dǎo)出csv文件及導(dǎo)入csv文件到數(shù)據(jù)庫(kù)操作_Mysql

這篇文章主要介紹了mysql實(shí)現(xiàn)查詢結(jié)果導(dǎo)出csv文件及導(dǎo)入csv文件到數(shù)據(jù)庫(kù)操作,結(jié)合實(shí)例形式分析了mysql相關(guān)數(shù)據(jù)庫(kù)導(dǎo)出、導(dǎo)入語(yǔ)句使用方法及操作注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了mysql實(shí)現(xiàn)查詢結(jié)果導(dǎo)出csv文件及導(dǎo)入csv文件到數(shù)據(jù)庫(kù)操作。分享給大家供大家參考,具體如下:

mysql 查詢結(jié)果導(dǎo)出csv文件:

select?logtime,?operatingsystem,?imei from?GameCenterLogs where ??operatingsystem?&gt;=?1?and?operatingsystem?<p>fields TERMINATED BY ',' 設(shè)置字段的分割符</p><p>OPTIONALLY ENCLOSED BY '#' 設(shè)置字段內(nèi)容若為字符串,則使用'#'包含</p><p>LINES TERMINATED BY 'rn' 數(shù)據(jù)行分割符</p><p>導(dǎo)出文件內(nèi)容:</p><blockquote>1453513680,3,#hello word#rn1453515470,2,#title content#rn</blockquote><p><strong>mysql命令行導(dǎo)入csv文件到數(shù)據(jù)庫(kù):</strong></p><pre class="brush:sql;">load?data?infile?'/tmp_logs/tmp.csv' into?table?GameCenterDAULogs?fields?terminated?by?','?OPTIONALLY?ENCLOSED?BY?'#'?lines?terminated?by?'rn'

有可能操作系統(tǒng)不同,導(dǎo)出的csv文件的數(shù)據(jù)行分隔符不一定為rn,可以使用cat -A /tmp_logs/tmp.csv 查看結(jié)尾符

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊8 分享