我正在编写一个shell脚本来从mysql数据库(实际上是数据库的一部分,从一个特定的时间段到另一个时间段)获取表,并将其放入.csv文件中。这是我写的内容,我得到了一个错误
mysql -u -p -B -e "use mytable;select * from table3;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > filename.csv(mysql的多个查询)
(请同时提示如何从mysql表中提取特定时间段的数据,例如Jan 23 16:05到Jan 30 17:05)
请注意,table3将来自外壳变量newtable,因此我必须在代码中使用$newtable,并且只能使用外壳
发布于 2013-08-22 14:50:12
在脚本中使用newtable:
newtable="table3"
"mysql -u -p -B -e "use mytable;select * from $newtable;"对于查询部分,假设您使用的是名称为"period“的"date type”列,则查询将为:
"Select * from table3 where MONTHNAME(period)='January';请根据您的要求检查此最新更新:
date="2010-08-11"
start="10:09:09"
end="21:50:59"
"Select * from table3 where DATE(period)='$date' and TIME(period) between
'$start'and '$end'";发布于 2013-08-22 16:44:14
如果您可以使用mysql查询csv文件:
echo "SELECT a,b,a+b INTO OUTFILE‘/tmp/result.txt t.txt’以',‘结尾的字段可选由'"’FROM $newtable '\n‘结尾的行;“| mysql -u -p -B mytable
更多信息:http://dev.mysql.com/doc/refman/5.1/en/select-into.html
https://stackoverflow.com/questions/18372806
复制相似问题