Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

how to take mysqldump of latest 1000 records from a database

share|improve this question

1 Answer 1

mysqldump has a --where option. Assuming you have some sort of toehold to figure out what the last 1000 inserted records are (for instance, an auto-increment field called id), you should be able to tack that onto the mysqldump command, like so:

mysqldump --where "1=1 ORDER BY id DESC LIMIT 1000" DB_NAME TBL_NAME

The 1=1 is necessary because the "WHERE" keyword is inserted into the query automatically so you do have to give it some SQL to evaluate.

share|improve this answer
I did what you suggest and I upvoted your answer, but, what about integrity constraint violation? –  licorna Sep 21 '11 at 21:59
That's a whole other problem. My solution is a hack at best. If you want integrity for putting the rows back in somewhere else, that's going to be a tougher problem and very dependent on your design –  jj33 Sep 22 '11 at 14:01

Your Answer


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.