HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

mysqldump: replace drop table in output with delete?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
deletewithmysqldumpreplaceoutputdroptable

Problem

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?

Solution

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 !!!

Code Snippets

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

Context

StackExchange Database Administrators Q#46807, answer score: 4

Revisions (0)

No revisions yet.