Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to get the data from mysql server and export to .csv file .i need to export data to new .csv file daily automatically.

query:select count(*) count,create_date from tabpush where status=1 and create_date between '2015-12-05' AND '2015-12-06' order by create_date desc ;

how do i do that ? i am new to shell script.

env:

linux:centos6.6

share|improve this question
    
This query appears to produce only one row with one column. You want to put that in a .csv file? – RobertL Dec 9 '15 at 2:35
    
@RobertL Thanq for reply ,yes i need to put what that query returns into csv file – naveen Dec 9 '15 at 2:41
    
You can use SELECT .. INTO outfile (see dev.mysql.com/doc/refman/5.7/en/select-into.html ) to write a table to a text file with comma as a field delimeter and a newline as a record delimeter. – DopeGhoti Dec 9 '15 at 8:58

You can achieve this easily with MySQL's select ... into outfile. Like this for example:

select count(*) count,create_date from tabpush 
where status=1 and create_date between subdate(current_date, 1) AND current_date()
order by create_date desc
INTO OUTFILE '/tmp/daily.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.