MySQL - 从csv文件导入88000行仅插入39行

时间:2017-09-07 20:02:18

标签: mysql sql csv

我正在尝试将包含+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

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分: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 :(得分:0)

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