views:

82

answers:

1

I have a webapp that spans many different users, each with selective permissions about what they are able to see. The app is built on top of a MySQL database.

One feature I am interested in providing to my "power users" is a sql dump of all their data so that they can run off and do their own things with it. Now I can't just use mysqldump because there are things belonging to other users that should not be made available to anybody else on download.

Is there any other easy way to get data in and out of MySQL that allows you to selectively specify what to export, and without having to jump through all kinds of hoops? Note that I need control at the query level - i.e. being able to specify a list of tables is NOT sufficient. In an ideal world, such a tool would automatically find all relationships based on traversal of foreign keys, but if I have to write queries at the table-level I'm willing to, provided it's easy for others to get the data back into mysql without too much trouble.

Anyone know if such a tool exists, or if I am in "roll my own" territory?

+1  A: 

Mysqldump does have a "--where" flag that you can use to selectively return rows. I think you should be able to do something like:

mysqldump --where="foreign_key_id=5"

Which should return only those specific rows, more documentation on the MySQL Site

However, I'm not sure you wouldn't be further ahead to do an export as comma separated value files. CSV files can be imported back into MySQL as well as give your users many other options for ways to work with their data (spreadsheets, other RDBMS, text analysis).

Mike Buckbee
True on csvs, although we are talking about 20+ tables at a minimum. Does mysql support a bulk import of csv data?
Cory
Yes, if you use the mysqlimport tool it will automatically create the tables based on the filenames you input docs for mysqlimport at http://dev.mysql.com/doc/refman/5.0/en/mysqlimport.html 
Mike Buckbee