Home > Database > Mysql Tutorial > MySQL按属性字段导出CSV数据

MySQL按属性字段导出CSV数据

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:40:01
Original
1415 people have browsed it

因为需要导出一张表的数据成csv格式格式文件。需要根据表中的日期字段自动导成一个文件。可以用下面代码实现: date_start='2013-12-01'date_end='2013-12-03'date_n=$date_startwhile(true)doif [[ $date_n $date_start || $date_n $date_end ]];thenbreak;

因为需要导出一张表的数据成csv格式格式文件。需要根据表中的日期字段自动导成一个文件。可以用下面代码实现:

date_start='2013-12-01'
date_end='2013-12-03'
date_n=$date_start
while(true)
do
	if [[ $date_n  $date_end ]];then
		break;
	else
		mysql -uroot -p'*****' -e " select word,num from  testmirror.hotsearch where DAY= '$date_n' into outfile '/tmp/mysql/hostsearch.$date_n.csv' fields terminated by ','  lines terminated by '\n';"
		date_n=$(date -d "$date_n +1day" +%F) 
                echo $date_n
	fi
done
Copy after login

说明:
设置表中数据的开始结束日期:
date_start=’2013-12-01′
date_end=’2013-12-03′

outfile 需要设置777权限

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template