mysql没有读取整个文件,而是在使用“本地加载数据”时跳过行`
在我的一个作业问题中,我需要读取一个有131262行的输入文件 以下是我读取输入的代码:mysql没有读取整个文件,而是在使用“本地加载数据”时跳过行`,mysql,load-data-infile,Mysql,Load Data Infile,在我的一个作业问题中,我需要读取一个有131262行的输入文件 以下是我读取输入的代码: create table batsman_scored( id int(10) unsigned auto_increment primary key, match_id int(10), over_id int(10), ball_id int(10), runs_scored int(10), innings_no int(10) ); load data
create table batsman_scored(
id int(10) unsigned auto_increment primary key,
match_id int(10),
over_id int(10),
ball_id int(10),
runs_scored int(10),
innings_no int(10)
);
load data local infile "data/batsman_scored.csv"
into table batsman_scored
fields terminated by ','
lines terminated by '\n'
ignore 2 rows
;
问题是,出于某种原因,MySQL没有读取整个文件,而是在几行之后就被终止了。我检查了输入文件,没有任何可疑之处。
Mysql输出:
Query OK, 568 rows affected, 65535 warnings (0.50 sec)
Records: 131260 Deleted: 0 Skipped: 130692 Warnings: 261952
有人能告诉我,为什么要跳过这么多行?MySQL何时跳过行
我检查过MySQL可以存储比568
多得多的内容
我仍在等待答案,但在评论
自动增量
行时:
create table batsman_scored(
// id int(10) unsigned auto_increment primary key,
match_id int(10),
over_id int(10),
ball_id int(10),
runs_scored int(10),
innings_no int(10)
);
load data local infile "data/batsman_scored.csv"
into table batsman_scored
fields terminated by ','
lines terminated by '\n'
ignore 2 rows
;
使用
创建击球手得分表(
id int(10)无符号自动递增主键,
匹配id int(10),
超过(10),
球头内径(10),
跑步得分(10分),
局数(10)
);
加载数据本地填充“数据/batsman_scored.csv”
击球手吴进了一球
以“,”结尾的字段
以“\n”结尾的行
忽略2行
(比赛id、过球id、球id、得分、局数)
;
id
列的值不存储在CSV中(该表包含6列,而CSV每行包含5个值),它们不会从文件中加载,而是在导入过程中通过自动增量生成。因此,必须指定要加载的列列表,w/oid
column。如果在加载数据期间发生错误,则不会从表中截断已加载的行。请检查第569行是否不正确。您的CSV每行包含10个值,而表结构仅包含6列!表中的st copumn是主键,而CSV中的第1列包含重复项。最后,您的表结构与CSV数据不匹配。对不起,我刚刚更新了CSV链接。为什么我不能在这里使用自动增量功能?我想用它作为主键?这一个有效。谢谢。@AnupamKumar请注意-在CSV中指定了复合主键。因此,要么从结构中删除id
,并按照CSV中的指定创建复合PK,要么根据CSV头中的数据创建复合唯一键。Sry对于CSV文件中说明的键入,这些不能用作主键。我必须在这个表中添加一些主键,所以我添加了自动增量行。