Export a database subset

I ran into an interesting bit of code today. Sometimes a database gets too big and you only want the structure. In that situation, there’s the -d parameter. In other cases, you want not only the structure, but some of the data too. By using the –where parameter creatively, we can limit the number of rows mysqldump returns.

mysqldump --where="true LIMIT X" schema > output.sql

Unfortunately, this doesn’t allow for any granularity in the number of rows returned. Still, “get me the database and at most 1000 rows from each table” can be helpful in certain situations.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>