Reputation: 833
I am copying records from one table to another and there is a chance that some records may already be in the second table i am copying the records to.
Since there are lots of rows i am copying,i am looking a way to ignore all the record already exists messages from mysql and continue executing the mysql file.
Is there a way i can suppress the error messages?.
Upvotes: 1
Views: 708
Reputation: 625
Try this:
zcat db.sql.gz | sed -e 's/INSERT/INSERT IGNORE/' | mysql -u user -p dbname
Upvotes: 0
Reputation: 125945
As documented under INSERT
Syntax:
The
INSERT
statement supports the following modifiers:[ deletia ]
- If you use the
IGNORE
keyword, errors that occur while executing theINSERT
statement are treated as warnings instead. For example, withoutIGNORE
, a row that duplicates an existingUNIQUE
index orPRIMARY KEY
value in the table causes a duplicate-key error and the statement is aborted. WithIGNORE
, the row still is not inserted, but no error is issued.
Upvotes: 4