Here is what i did in the terminal. The idea is basically to get a list of all tablenames, and then pipe it into a while loop in bash where each of those tables are dumped into a separate dumpfile individually.
mysql --user=superman --password=batman --host=gothamcity.rds.com --port=3306 --database=jokersbox --execute="show tables" --silent --batch | while read tablename ; do mysqldump --user=superman --password=batman --host=gothamcity.rds.com --port=3306 --where="1=1 ORDER BY id DESC LIMIT 10" jokersbox $tablename --add-drop-table > $tablename.sql ; done
It worked. Only issue is, it dumped each table into it's own individual SQL file - not all tables were dumped to a single file. But i guess the contents of those individual files could also be joined together into a single file via some other bash commands.
EDIT::: you can use the >>
operator instead of the >
operator to append each mysqldump to a single file instead of overwriting the file with the last mysqldump. If you choose to use >>
you must ensure that you write to a fixed filename (like dumps.sql
) instead of writing to a dynamic filename (like $tablename.sql
). You must also make sure that there is no dumps.sql
file present prior to running the script - otherwise, your mysqldumps will get appended to a file which already has other contents in them.