I am inserting some data into a table, but it occasionally clashes with other data in the table (ie. it has the same primary key).
I would like to be able to just overwrite this data if it is there, instead of having mysql send me an error message saying that their is a duplicate primary key. I know that I can just delete these values before hand, but it would take a somewhat large query.
Is it possible to overwrite these somehow and suppress any warnings, or am I forced to remove these values.
解决方案
Just a little cheatsheet.
Mysql has 3 different scenarios for handling unique key duplicates:
If you want to...
do nothing - use INSERT IGNORE
delete existing and create new - use REPLACE INTO
update existing - use ON DUPLICATE UPDATE