MySQL导出多字段数据之间有分隔符

举例;把一个表里面多个字段查询导出后用‘|’隔开,

 

mysql -uroot -p111111 -h1.1.1.1 -P3306 -e "use databases;set names utf8;select a,'|' as a,b,'|' as b,c, '|' as c,d,'|' as d, e,'|' as e,f,'|' as f,update_date,'|' as date from table_name;"|gzip >xx2.txt.gz

 

查询结果如下:

MySQL导出多字段数据之间有分隔符_第1张图片

 

假如对时间有要求:

 

mysql -uroot -p111111 -h11.1.1.1 -P3306 -e "use databases;set names utf8;select id,'|' as id,sh,'|' as h,_mc,'|' as mc,r,'|' as dr,date_format(jdrq,'%Y-%m_%d') as jdrq, '' as rq, date_format(sjc, '%Y-%m-%d') as sjc, '|' as sjc, update_date from table-name;"|gzip >x.txt.gz

 

MySQL导出多字段数据之间有分隔符_第2张图片

你可能感兴趣的:(MySQL导出多字段数据之间有分隔符)