Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysqldump using where clause with current date or date range

Status
Not open for further replies.

fpalero

MIS
Jan 10, 2017
6
PH
Hi,

Anyone can help on how to mysqldump using where clause with date range, i have sql statement but it will not generated an output needed like in "with data :".

table definition : testtab1

field definition :
| uploaded_date | timestamp | NO | | CURRENT_TIMESTAMP

with data :
+---------------------+
| uploaded_date |
+---------------------+
| 2017-05-05 03:00:15 |
| 2017-05-05 03:00:24 |
| 2017-05-05 03:00:29 |
| 2017-05-05 03:00:33 |
| 2017-05-05 03:00:34 |
| 2017-05-05 03:00:38 |
| 2017-05-05 03:00:43 |
| 2017-05-05 03:00:44 |
| 2017-05-05 03:00:46 |
| 2017-05-05 03:00:50 |
| 2017-05-05 03:01:03 |
| 2017-05-05 03:01:03 |
+---------------------+

SQL Statement :

First test : not generating output like "with data :"
# fnow=$(date +"%Y-%m-%d 00:00:00")
# tnow=$(date +"%Y-%m-%d 23:59:59")
# mysqldump -uuatusr01 -puatusr@01 -t -c -n --where="(uploaded_date>='$fnow' and uploaded_date<='$tnow')" uatdb testtab1 > output.sql

Second test : not generating output like "with data :"
# mysqldump -uuatusr01 -puatusr@01 -t -c -n --where="date_format(uploaded_date,'%Y%m%d')=date_for mat(now(),'%Y%m%d')" uatdb testtab1 > output.sql

Thanks in advanced.

Regards
Fpalero



 
Would not using "into outfile" be simpler?

SQL:
SELECT 'columns' INTO OUTFILE 'path-to-file.sql' FROM 'table' WHERE criteria;

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top