我对MySQL很新,但我无法找到为什么我无法从命令行将csv文件导入我的数据库。输入文件对于PHPMyAdmin来说太大了,然后我尝试从命令行更新数据表。
这是从终端
运行的命令LOAD DATA LOCAL INFILE "/home/meteo/PROJECTES/BASE-AEMET/TREBALL/PCP.csv" into TABLE precipitacion FIELDS TERMINATED BY ',' (CodigoEst, Fecha, Precipitacion, ValidPP);
这些是PCP.csv文件的结构
"7034",2000-01-01,0,"S"
"7034",2000-02-01,0,"S"
"7034",2000-03-01,0,"S"
"7034",2000-04-01,0,"S"
"7034",2000-05-01,0,"S"
但是sql查询的输出给出了这条消息
查询正常,0行受影响,65535警告(30,55秒)记录:1586445 删除:0跳过:1586445警告:4759335
并且表格中没有插入任何记录。
在查看警告时,我收到此消息
mysql> SHOW WARNINGS \G
*************************** 1. row ***************************
Level: Warning Code: 1265 Message: Data truncated for column 'CodigoEst' at row 1
*************************** 2. row ***************************
Level: Warning Code: 1265 Message: Data truncated for column 'ValidPP' at row 1
*************************** 3. row ***************************
Level: Warning Code: 1062 Message: Duplicate entry '"7034-2000-01-01' for key 'PRIMARY'
*************************** 4. row ***************************
Level: Warning Code: 1265 Message: Data truncated for column 'CodigoEst' at row 2
*************************** 5. row ***************************
Level: Warning Code: 1265 Message: Data truncated for column 'ValidPP' at row 2
*************************** 6. row ***************************
Level: Warning Code: 1062 Message: Duplicate entry '"7034-2000-02-01' for key 'PRIMARY'
*************************** 7. row ***************************
Level: Warning Code: 1265 Message: Data truncated for column 'CodigoEst' at row 3
*************************** 8. row ***************************
Level: Warning Code: 1265 Message: Data truncated for column 'ValidPP' at row 3
*************************** 9. row ***************************
Level: Warning Code: 1062 Message: Duplicate entry '"7034-2000-03-01' for key 'PRIMARY'
*************************** 10. row ***************************
Level: Warning Code: 1265
如何进行?愿这是一个简单的问题,但我被困在这里。在此先感谢您的帮助。
编辑1
添加@jacktherandom注释中建议的输出
mysql> show CREATE TABLE precipitacion
-> ;
+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| precipitacion | CREATE TABLE `precipitacion` (
`CodigoEst` char(5) NOT NULL DEFAULT '',
`Fecha` date NOT NULL,
`Precipitacion` decimal(5,1) DEFAULT NULL,
`ValidPP` enum('N','S','A') NOT NULL DEFAULT 'N',
PRIMARY KEY (`CodigoEst`,`Fecha`),
KEY `Grupos_CodigoEst` (`CodigoEst`),
KEY `Grupos_Fecha` (`Fecha`),
KEY `Grupos_ValidPP` (`ValidPP`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0,00 sec)
答案 0 :(得分:0)
Code: 1265 Message: Data truncated for column
表示您插入的值大于列允许的值。
Code: 1062 Message: Duplicate entry
表示您为具有UNIQUE
键的列插入值,并且该值已存在于该列的另一行中。
答案 1 :(得分:0)
最后,将数据导入我的数据库的解决方案是将原始的大csv拆分为较小的文件。然后,从phpMyAdmin导入运行正常。
感谢您的建议。