# mysqldump --replace
flag
The mysqldump
command has a --replace
flag that can be used to generate REPLACE INTO
statements instead of INSERT INTO
statements in the SQL script.
REPLACE INTO
statements are similar to INSERT INTO
statements, but if a row already exists with the same primary key or unique index, the REPLACE INTO
statement will delete the old row and insert a new one in its place. If the row does not exist, it will be inserted as a new row.
Here is an example of how to use the --replace
flag:
mysqldump my_app --replace > my_backup.sql
This will create a my_backup.sql
SQL file with REPLACE INTO
statements instead of INSERT INTO
.
# When to use the --replace
flag?
The --replace
flag can be useful if you want to update existing rows with new data.