Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error 1062. Duplicate entry in mysql

I have a MySQL table whose schema in which column 1 is primary key. I have a tsv file which I need to insert in this table. Now, the tsv has repetition of primary key hence when I try to insert it in MySQL table it gives an error

ERROR 1062 (23000): Duplicate entry '107664521128181760' for key
'PRIMARY'

Is there any way by which if the primary key value already exists, then it should ignore and move further for next insertion.

like image 411
Saurabh Avatar asked Nov 22 '25 01:11

Saurabh


1 Answers

You are probably looking for INSERT IGNORE INTO command.

You can try like this:

INSERT IGNORE INTO yourtablename(col1,col2...)
values(val1,val2,...)
like image 172
Rahul Tripathi Avatar answered Nov 25 '25 00:11

Rahul Tripathi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!