Thursday, July 1, 2010

How to export only data using mysqldump and grep?

I just found a way to export only data using mysqldump:

mysqldump -u root -p --skip-opt --skip-set-charset --skip-quote-names --skip-tz-utc --skip-add-drop-table --skip-add-drop-table --skip-comments --no-create-info --skip-add-locks --skip-triggers databasename table1 table2 > data.sql

Now data.sql will contain only the insert statements but needs a bit of cleanup:

grep -iv '!4' data.sql > final_data.sql

This should have only insert statements and nothing else.

There might be some other better way!! but this works for me :P

No comments: