错误1062.在mysql中重复的条目 [英] Error 1062. Duplicate entry in mysql

查看:183
本文介绍了错误1062.在mysql中重复的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MySQL表,该表的架构中第1列是主键. 我有一个tsv文件,需要在此表中插入.现在,tsv具有重复的主键,因此当我尝试将其插入到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.

推荐答案

这取决于您如何导入数据.

It depends on how you are importing the data.

如果您正在使用LOAD DATA INFILE命令,则在命令中使用IGNORE如下:

If you are using LOAD DATA INFILE command then use IGNORE in command as:

LOAD DATA INFILE 'member.tsv'
IGNORE INTO TABLE tbl_member
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
(name, age);

如果您使用的是具有INSERT命令的sql,请在INSERT命令中使用INSERT IGNORE:

And if you are using sql having INSERT command then use INSERT IGNORE in INSERT command as:

INSERT IGNORE INTO yourtablename(col1,col2...)
values(val1,val2,...)

这篇关于错误1062.在mysql中重复的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆