snippetsqlMinor
How to Skip Existing Data While Restoring mysqldump File?
Viewed 0 times
filewhilemysqldumpskiprestoringhowexistingdata
Problem
I use this query to import data using MySQL Dump (Command Prompt / Command Line)
I want to import the large database (only new deltas) as of now I drop database and re-import but I want to import only new deltas.
mysql -u root -p database_name < database_name.sqlI want to import the large database (only new deltas) as of now I drop database and re-import but I want to import only new deltas.
Solution
I have four(4) suggestions:
SUGGESTION #1 : Recreate dump with
Use --insert-ignore
Write INSERT IGNORE statements rather than INSERT statements.
What happens on reload ???
SUGGESTION #2 : Change
Instead of loading normally
just pipe the dump into sed and reload like this:
SUGGESTION #3 : Recreate dump with
Use --replace
Write REPLACE statements rather than INSERT statements.
What happens on reload ???
SUGGESTION #4 : Change
Instead of loading normally
just pipe the dump into sed and reload like this:
SUMMARY
GIVE IT A TRY !!!
SUGGESTION #1 : Recreate dump with
INSERT IGNOREUse --insert-ignore
Write INSERT IGNORE statements rather than INSERT statements.
What happens on reload ???
- New data gets inserted.
- Already existing primary keys are skipped
SUGGESTION #2 : Change
INSERT to INSERT IGNORE on reloadInstead of loading normally
mysql -u root -p database_name < database_name.sqljust pipe the dump into sed and reload like this:
cat database_name.sql|sed 's/^INSERT/INSERT IGNORE/'|mysql -u root -p database_nameSUGGESTION #3 : Recreate dump with
REPLACE INTOUse --replace
Write REPLACE statements rather than INSERT statements.
What happens on reload ???
- New data gets inserted.
- Already existing primary keys will be deleted and re-inserted
SUGGESTION #4 : Change
INSERT INTO to REPLACE INTO on reloadInstead of loading normally
mysql -u root -p database_name < database_name.sqljust pipe the dump into sed and reload like this:
cat database_name.sql|sed 's/^INSERT INTO/REPLACE INTO/'|mysql -u root -p database_nameSUMMARY
- Use suggestions 1 or 3 if you can recreate the dump
- Use suggestions 2 or 4 if you cannot recreate the dump
GIVE IT A TRY !!!
Code Snippets
mysql -u root -p database_name < database_name.sqlcat database_name.sql|sed 's/^INSERT/INSERT IGNORE/'|mysql -u root -p database_namemysql -u root -p database_name < database_name.sqlcat database_name.sql|sed 's/^INSERT INTO/REPLACE INTO/'|mysql -u root -p database_nameContext
StackExchange Database Administrators Q#274218, answer score: 4
Revisions (0)
No revisions yet.