Retrieve N last rows from a mysqldump
I'm using the following command to dump 100 rows from each column from each database. The problem is that it returns the first 100 records where I would much rather have the last. I found a flag that lets me order by primary key (--order-by-primary), but that still returns the wrong rows. I would try to sneak an 'order by' into the where flag below, but the primary key is different for each table.
mysqldump -u username -p --where="true limit 100" --all-databases > dump.sql
Is there a way to reverse the order before grabbing the last 100 records or perhaps a way of referring to the开发者_StackOverflow社区 PK rather than the PK's column name?
I think as long as you don't want to patch the mysqldump source code there is just a workaround.
Try creating a secondary database schema (scheme_dump) and make a script which loops over all tables, fires
create table scheme_dump.<tabname> like <tabname>;
insert into scheme_dump.<tabname> select * from <tabname> order by <colname> desc limit 100;
and then dump scheme_dump scheme.
Not nice.
But fixing the source code for a one-shot should not be that hard.
May be this : SELECT * FROM TableName ORDER BY DESC LIMIT 100
精彩评论