【问题标题】:MySQL - importing 88000 rows from a csv file inserts only 39 rowsMySQL - 从 csv 文件导入 88000 行仅插入 39 行
【发布时间】:2017-09-07 20:02:18
【问题描述】:

我正在尝试将包含 +88000 个条目的 csv 文件导入我使用以下查询创建的表 xyz:

LOAD DATA LOW_PRIORITY LOCAL INFILE 
'C:\\Users\\Simo\\Desktop\\file.csv' IGNORE INTO TABLE
`complete`.`xyz` FIELDS TERMINATED BY ',' 
LINES TERMINATED BY 'auto' 
(`datetime`, `city`, `state`, `country`, `shape`, `duration (seconds)`, `duration (hours/min)`, `comments`, `date posted`, `latitude`, `longitude`)

只插入了 39 行,因为这是我得到的输出:

Query OK, 39 rows affected, 149 warnings (0.23 sec)
Records: 39  Deleted: 0  Skipped: 0  Warnings: 149

警告:

Warning | 1265 | Data truncated for column 'longitude' at row 1                                                                                                                                               |
| Warning | 1262 | Row 1 was truncated; it contained more data than there were input columns                                                                                                                    |
| Warning | 1265 | Data truncated for column 'country' at row 2                                                                                                                                                 |
| Warning | 1366 | Incorrect decimal value: '"White lights race through the sky in clear daylight&#44 fighters in persuit"' for column 'longitude' at row 2                                                     |
| Warning | 1262 | Row 2 was truncated; it contained more data than there were input columns                                                                                                                    |
| Warning | 1261 | Row 3 doesn't contain data for all columns                                                                                                                                                   |
| Warning | 1261 | Row 3 doesn't contain data for all columns                                                                                                                                                   |
| Warning | 1261 | Row 3 doesn't contain data for all columns                                                                                                                                                   |
| Warning | 1261 | Row 3 doesn't contain data for all columns                                                                                                                                                   |
| Warning | 1265 | Data truncated for column 'country' at row 4                                                                                                                                                 |
| Warning | 1366 | Incorrect decimal value: '"Bright orb and strange craft flying over Vancouver&#44 Wa"' for column 'longitude' at row 4                                                                       |
| Warning | 1262 | Row 4 was truncated; it contained more data than there were input columns                                                                                                                    |
| Warning | 1261 | Row 5 doesn't contain data for all columns                                                                                                                                                   |
| Warning | 1261 | Row 5 doesn't contain data for all columns                                                                                                                                                   |
| Warning | 1261 | Row 5 doesn't contain data for all columns                                                                                                                                                   |
| Warning | 1261 | Row 5 doesn't contain data for all columns                                                                                                                                                   |
| Warning | 1265 | Data truncated for column 'country' at row 6                                                                                                                                                 |
| Warning | 1265 | Data truncated for column 'shape' at row 6                                                                                                                                                   |
| Warning | 1366 | Incorrect decimal value: '"North Kansas City UFO"' for column 'longitude' at row 6                                                                                                           |
| Warning | 1262 | Row 6 was truncated; it contained more data than there were input columns                                                                                                                    |
| Warning | 1265 | Data truncated for column 'duration (hours/min)' at row 7                                                                                                                                    |
| Warning | 1265 | Data truncated for column 'latitude' at row 7                                                                                                                                                |
| Warning | 1366 | Incorrect decimal value: 'lisbon' for column 'longitude' at row 7                                                                                                                            |
| Warning | 1262 | Row 7 was truncated; it contained more data than there were input columns                                                                                                                    |
| Warning | 1265 | Data truncated for column 'country' at row 8                                                                                                                                                 |
| Warning | 1366 | Incorrect decimal value: '"ufos playing in the night sky near the southern cross star cluster"' for column 'longitude' at row 8                                                              |
| Warning | 1262 | Row 8 was truncated; it contained more data than there were input columns                                                                                                                    |
| Warning | 1265 | Data truncated for column 'datetime' at row 9                                                                                                                                                |
| Warning | 1265 | Data truncated for column 'country' at row 9                                                                                                                                                 |
| Warning | 1366 | Incorrect decimal value: '"Two craft 3 miles from each other close to the ground seen by two in Central Washington November 1999"' for column 'longitude' at row 9                           |
| Warning | 1262 | Row 9 was truncated; it contained more data than there were input columns                                                                                                                    |
| Warning | 1265 | Data truncated for column 'duration (hours/min)' at row 10                                                                                                                                   |
| Warning | 1265 | Data truncated for column 'latitude' at row 10                                                                                                                                               |
| Warning | 1366 | Incorrect decimal value: 'rockwall' for column 'longitude' at row 10                                                                                                                         |
| Warning | 1262 | Row 10 was truncated; it contained more data than there were input columns                                                                                                                   |
| Warning | 1265 | Data truncated for column 'datetime' at row 11                                                                                                                                               |
| Warning | 1265 | Data truncated for column 'country' at row 11                                                                                                                                                |
| Warning | 1366 | Incorrect decimal value: '"Shiny golden metallic sphere gliding across the skies of Atlanta&#44 GA. December 15&#44 1998&#44 09:07am."' for column 'longitude' at row 11                     |
| Warning | 1262 | Row 11 was truncated; it contained more data than there were input columns                                                                                                                   |
| Warning | 1265 | Data truncated for column 'duration (hours/min)' at row 12                                                                                                                                   |
| Warning | 1265 | Data truncated for column 'latitude' at row 12                                                                                                                                               |
| Warning | 1366 | Incorrect decimal value: 'seaford' for column 'longitude' at row 12                                                                                                                          |
| Warning | 1262 | Row 12 was truncated; it contained more data than there were input columns                                                                                                                   |
| Warning | 1265 | Data truncated for column 'country' at row 13                                                                                                                                                |
| Warning | 1265 | Data truncated for column 'shape' at row 13                                                                                                                                                  |
| Warning | 1366 | Incorrect decimal value: '"I am a graduate student at Western Kentucky University in Bowling Green.  I was on my way to an evening class.  I exited Cumber' for column 'longitude' at row 13 |
| Warning | 1262 | Row 13 was truncated; it contained more data than there were input columns                                                                                                                   |
| Warning | 1265 | Data truncated for column 'datetime' at row 14                                                                                                                                               |
| Warning | 1265 | Data truncated for column 'country' at row 14                                                                                                                                                |
| Warning | 1366 | Incorrect decimal value: '"I was driving north on HWY 101 over the hill from Peteluma to Cotati when I saw a green/blue orb pass in front of my car in the' for column 'longitude' at row 14 |
| Warning | 1262 | Row 14 was truncated; it contained more data than there were input columns                                                                                                                   |
| Warning | 1265 | Data truncated for column 'country' at row 15                                                                                                                                                |
| Warning | 1366 | Incorrect decimal value: '"Floating bell shaped object with pure white lights tinged with silver angel or ufo?"' for column 'longitude' at row 15                                            |
| Warning | 1262 | Row 15 was truncated; it contained more data than there were input columns                                                                                                                   |
| Warning | 1265 | Data truncated for column 'country' at row 16                                                                                                                                                |
| Warning | 1366 | Incorrect decimal value: '"Red Orbs."' for column 'longitude' at row 16                                                                                                                      |
| Warning | 1262 | Row 16 was truncated; it contained more data than there were input columns                                                                                                                   |
| Warning | 1265 | Data truncated for column 'country' at row 17                                                                                                                                                |
| Warning | 1265 | Data truncated for column 'shape' at row 17                                                                                                                                                  |
| Warning | 1366 | Incorrect decimal value: '"MUFON member reports gigantic&#44 black ship passes NNE over house at 5 mph. 20 min sighting. Good rept."' for column 'longitude' at row 17                       |
| Warning | 1262 | Row 17 was truncated; it contained more data than there were input columns                                                                                                                   |
| Warning | 1265 | Data truncated for column 'datetime' at row 18                                                                                                                                               |
| Warning | 1265 | Data truncated for column 'country' at row 18                                                                                                                                                |
| Warning | 1265 | Data truncated for column 'shape' at row 18                                                                                                                                                  |

我想知道为什么文件包含超过88000行数据时它只插入39行?

无论有任何警告或错误,我如何让它继续插入?

这是我要导入的 csv 文件:File

【问题讨论】:

  • 'auto' 更改为'\n' 以使用换行符,并添加找到here 的“可选括起来”
  • 有效!!!请写一个答案,我会将其标记为已接受。非常感谢
  • 很高兴能帮上忙!

标签: mysql sql csv


【解决方案1】:

这里有两个问题:它希望以单词“auto”而不是新行结束行,并且一些(但只有一些)字符串用引号引起来。所以你需要像这样调整查询:

LOAD DATA LOW_PRIORITY LOCAL INFILE 
    'C:\\Users\\Simo\\Desktop\\file.csv' IGNORE INTO TABLE
      `complete`.`xyz` FIELDS TERMINATED BY ',' 
      OPTIONALLY BY '"'
      LINES TERMINATED BY '\n' 
    (`datetime`, `city`, `state`, `country`, `shape`, `duration (seconds)`, `duration (hours/min)`, `comments`, `date posted`, `latitude`, `longitude`)

【讨论】:

  • 你是个传奇!
【解决方案2】:

您需要为每一行的所有列填写正确的数据,或者,您需要编辑表结构以允许您拥有的数据集。 IE,您需要允许空值并确保输入的值与列的数据类型匹配。

【讨论】:

    【解决方案3】:

    错误显示 CSV 文件中的每一行都不匹配列结构。与实际表结构相比,有些行包含的列数较多,有些行包含的列数较少。

    【讨论】:

      猜你喜欢
      • 2010-11-19
      • 2015-03-30
      • 2019-02-03
      • 2013-02-05
      • 1970-01-01
      • 2016-04-02
      • 2014-03-20
      • 1970-01-01
      相关资源
      最近更新 更多