2

I have an application that has a large database that includes, among many other tables, a table called content and a table called users.

I would like to set up a development environment for this application, however I would like to bring in only some parts of the content and users tables.

If there are 50,000 rows for each of these tables, I only want to bring over 10 rows so my development environment has at least some data.

What is the best way to create a dump of the database data and structure, while also limiting the size of the dump and the risk of putting sensitive information in a development environment?

1

2 Answers 2

0
mysqldump --opt --where="1 limit 10" database

It's an SQL injection: The --where option is basically appended to a query of the form SELECT * from table WHERE , so in this case you get SELECT * from table WHERE 1 limit 10. Without the 1, you would have an invalid query. Specifying 1 for a where clause (since 1 is always true) simply selects all records.

Source: Limiting the number of records from mysqldump?

0

What is the best way to create a dump of the database data and structure, while also limiting the size of the dump and the risk of putting sensitive information in a development environment?

The best way to prevent sensitive data getting into your Development environment is not to put it there in the first place.

If you only want ten rows in each table, then write a SQL script to create those ten rows. That way, you have a consistent set of data that you can re-apply repeatably to your development database, any time you like.

If you were to take, say, the "first" ten rows from each table, then

  • There there's no guarantee that you'd get the same rows each time ("Rows have no intrinsic order"), so any dependent test cases would break,
  • You run the risk of pulling across sensitive data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.