1

To export data from a certain mysql table to xml I use the following command:

mysqldump --xml -t -u [username] --password=[password] [database] [table] > /path/to/file.xml

and it works just fine.
My problem is that it exports all columns from the table and I do not want this. I need the xml output for unit testing, so having a column "created_at" in the output would make all of my tests fail.

So my question is: assuming I have a mysql table called "Table", with columns "col_1, created, col_2", how can I mark "created" as column that will NOT be shown in the output xml file obtained via mysqldump command?

UPDATE: I cannot answer my question now, I will do it later. I needed it for PHPUnit, but actually instead of filtering mysqldump output, I can filter DataSet directly in PHPUnit.

  $filterDataSet = new PHPUnit_Extensions_Database_DataSet_DataSetFilter($notFilteredDataSet);
  $filterDataSet->setExcludeColumnsForTable('Table', array('created_at'));

will do what I need.

1 Answer 1

0

You can control which records get dumped by adding a WHERE clause to your mysqldump command (see http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_where).

2
  • that's indeed nice! what I need however is to control columns
    – mkk
    Apr 11, 2012 at 14:22
  • I misunderstood - thanks for clarifying. I would drop the column after importing the dump file: alter table drop column created_at. Then run your tests.
    – D Mac
    Apr 11, 2012 at 14:26

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.