Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am using mysqldump to dump some records in a table:

mysqldump mydatabase mytable --where="field=value"

this emits script that includes drop table mytable statement.

Since I use the --where option, when I replay the script, I want to overwrite only these records that satisfy the condition field=value. I want the emitted script to delete just these records:

delete from `mytable` where field=value

is there a way to achieve this?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Specify to not use any creation SQL with --no-create-info

mysqldump mydatabase mytable --no-create-info --where="field=value"

If you want to overwrite the records on reload of the mysqldump, just add --replace

mysqldump mydatabase mytable --no-create-info --replace --where="field=value"

I suggested --replace because REPLACE is a mechanical DELETE and INSERT.

Give it a Try !!!

share|improve this answer
    
thanks. this removes drop/create table. but how do I add the delete statement? –  akonsu Jul 22 '13 at 19:21
    
Updated my answer... –  RolandoMySQLDBA Jul 22 '13 at 20:34
    
thanks! suppose after I create a dump, a few more records got added to the table. I need to delete all records which satisfy the condition, and put the ones from the dump. I appreciate your help. looks like I cannot do it with just command line switches. –  akonsu Jul 22 '13 at 21:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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