English 中文(简体)
当表格中有一个列是 BIGINT 和独特的
原标题:issue with mysql LOAD DATA when table has a column that is BIGINT and unique

这张桌子的图案看起来像:

field - type - index

 id  - INT - PRI
 event_id  - BIGINT(20) - UNI
co1 ... colN (no indexes)

LOAD 数据命令 :

LOAD Data LOCAL IFILE 我的档案 改成可图的 mydb.myable (event_id, col1.colN.)

并获取错误 :

EROR 1062(23000),第1行:2147483647号重复条目,键1

键 1 指事件_id 上的独特密钥。

More context: (1) The table is empty at the time of LOAD DATA. (2) When I grep for 2147483647 in my source file I get nothing (3) 2147483647 is the integer max value (4) I am not actually inserting any value in id -- its just auto incrementing (5) I am using the REPLACE keyword in the LOAD DATA so even there were dupes, it should know how to deal with them?

这表明有些内在溢出问题(即,我不认为源数据或表格中存在任何真正的哑巴),事实上,我文件中的事件_id 值都超过最大整数限制。但是,错误是奇特的,因为事件编号列是 BIGINT 。

作为临时修正, 我丢弃了事件编号上的独特索引, 并且 LOAD DATA 命令有效! 事件编号中的值都是正常的, 没有缺省 。 因此处理值的表格没有问题, 但是 LOAD DATA 正在检查其独特性, 但它是一个整数?

有人遇到过类似的事情吗?

问题回答

这意味着, 2147483647 已经存在于数据库中一个标记为密钥的字段中。 只需从该字段中删除密钥, 您应该没事!

编辑 : 正如您在提问中所描述的那样, 事件_ id 是您的主要密钥 - 您不能在主密钥中拥有相同值的两倍 。

祝你好运!

问题不是数据类型,

问题是,您只有两个字段,一个是 PK,另一个是 UIQUE,所以不可能重复一个值。当您插入或装入数据时,它试图用此值添加两次“2147483647”的条目,您有几种方法来固定它。

  • 第一个尝试用文本编辑器打开文件, 找到重复的值并固定它, 如果它不使用 Mysqldump 或 phpmyadmin 来导出数据并在文本编辑器中编辑文件 。

  • 再次导出, 如果问题持续存在, 请尝试用其他方法( mysqldum 或 phpmyadmin) 导出数据再导入

  • 尝试在没有主密钥情况下重新创建表格, 您可以使用此选项

    create table big_int_test (select * from table1); and it will make a copy of the table without the PK, INDEXES and FK.

  • 您可以删除索引和 UIQUE 密钥限制, 导入数据, 修改表格( 删除重复值) 并重新创建 PK 和 UIQUE KEY (这有点疯狂, 但可能有效)





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签