MySQL exports CSV data by attribute Field

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.