Because you need to export the data of a table into a csv format file. You need to automatically export a file according to the date field in the table. You can use the following code: date_start2013-12-01date_end2013-12-03date_n $ date_startwhile (true) doif [[$ date_n $ date_start | $ date_n $ date_end]; thenbreak;
Because you need to export the data of a table into a csv format file. You need to automatically export a file according to the date field in the table. Use the following code: date_start = '2017-12-01 'date _ end = '2017-12-03' date _ n = $ date_startwhile (true) doif [[$ date_n $ date_start | $ date_n $ date_end]; thenbreak;
Because you need to export the data of a table into a csv format file. You need to automatically export a file according to the date field in the table. You can use the following code:
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;elsemysql -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_nfidone
Note:
Set the start and end dates of data in the table:
Date_start = '2017-12-01 ′
Date_end = '2017-12-03 ′
Outfile requires 777 permission
Original article address: MySQL exports CSV data by attribute field. Thank you for sharing it with the original author.