How to take a backup of only last year records from MySQL table to a file?
Asked
Active
Viewed 1,699 times
4
-
Why don't you just move the relevant data into another table and back up that table? – Shane Haw Aug 26 '13 at 07:41
2 Answers
0
This should work
mysqldump --databases X --tables Y --where="1 limit 1000000"
OR mysql cli
mysql -e "select * from myTable" -u myuser -pxxxxxxxxx mydatabase > mydumpfile.txt
Reference MySQL dump by query

Community
- 1
- 1

Rakesh Soni
- 10,135
- 5
- 44
- 51
0
Actually my requirement is like, we have one table with few years of data(approx 3 lac's records) based on the client requirement we have to keep only current year of data in the table remaining years data we have to take backup to a script and purge that data. I just tried the following code for backup. It's working fine. Please let me know is there any other way to do this simply.
mysqldump --add-lock test Employee -u root -n -t "--where=end_date between '1998-02-01' and '1998-08-30'" > sample.sql

Sarma Mullapudi
- 110
- 1
- 6