Using mysqldump with subqueries
I needed to dump some very specific portions of a large MySQL database; some of the data were second-degree relations (aka a Rails has-many-through). mysqldump won’t allow a join in the –where clause, but it will allow a subquery, so I ended up with something that looked a bit like this:
mysqldump --lock-all-tables --where 'id in (select user_id from memberships where site_id = 123)' my_database users
Handy, that. Thanks to Austriaco who was doing this in a similar context.
blog comments powered by Disqus