MySQL continue after Duplicate entry error

MySQL

I'm running a 'bash for' script to update some records in mysql, like so:

for i in `cat yahoo.txt`; do mysql $DB --batch -fe "update users set email=concat(left(email, instr(email, '@')), 'yahoo.com') where email like '%@$i';" ; done

but even with –force, the update stops after the first error:

ERROR 1062 (23000) at line 1: Duplicate entry 'example@yahoo.com' for key 3

Is there anyway I can force it to continue?

Best Answer

try changing update to update ignore

http://dev.mysql.com/doc/refman/5.0/en/update.html :

With the IGNORE keyword, the update statement does not abort even if errors occur during the update. Rows for which duplicate-key conflicts occur are not updated. Rows for which columns are updated to values that would cause data conversion errors are updated to the closest valid values instead.

Related Topic