1

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?.

1
  • I dont want to insert duplicate records. Commented Jul 15, 2013 at 14:44

2 Answers 2

4

As documented under INSERT Syntax:

The INSERT statement supports the following modifiers:

[ deletia ]
  • If you use the IGNORE keyword, errors that occur while executing the INSERT statement are treated as warnings instead. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row still is not inserted, but no error is issued.
Sign up to request clarification or add additional context in comments.

1 Comment

0

Try this:

zcat db.sql.gz | sed -e 's/INSERT/INSERT IGNORE/' | mysql -u user -p dbname

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.