如何解决mysql 不读取整个文件,而是在使用“本地加载数据”时跳过行
在我的一个作业问题中,我需要读取一个包含 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 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
(match_id,over_id,ball_id,runs_scored,innings_no)
;
id
列的值未存储在 CSV 中(该表包含 6 列,而 CSV 每行包含 5 个值),它们会从文件中加载,它们是在导入过程中通过自动增量生成的.因此必须指定用于加载的列列表,没有 id
列。
我仍在等待答案,但评论 auto_increment
行:
create table batsman_scored(
// id int(10) unsigned auto_increment primary key,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
;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。