Tuesday, February 12, 2013

Mysql querry problem

generally iam taking report by querry having statement :

select * from table_name where date(insert_time)='2010-11-01' INTO OUTFILE 'export_report.csv' FIELDS TERMINATED BY ',';

with help of this query i can generate report of perticular date. now I want to such that it shall pickup current date automatically. so that i dont need to insert date daily.
Pls help me.


Reply from Group Members


According to your suggestion i wrote following command includes querry. So that we can run directaly from bash prompt.
but when i execute this command command is not stoped automaticaly. and when i stop this command it generated file having size in gb.

mysql -u root -e "select * from table_name  where  date(insert_time)=CURDATE() INTO OUTFILE 'export_report.csv' FIELDS TERMINATED BY ',';  database_name
 

Or
 
select * from table_name where date CURDATE() INTO OUTFILE 'export_report.csv' FIELDS TERMINATED BY ',';

mysql> SELECT CURDATE();

+------------+

| CURDATE()  |

+------------+

| 2010-11-12 |

+------------+

1 row in set (0.01 sec)



mysql>
Its having 12973 entries when checked with

mysql > select count(*) from table_name;
one more thing i want to share that if i execute this query in mysql prompt with adding date manually then csv file generated having size of 2mb only..

No comments:

Post a Comment