导入csv文件时,mysql输入中的mysql无效列数 [英] mysql Invalid column count in CSV input while importing csv file
问题描述
我在数据库中有一个名为locations
的表,其中包含2列(id
会自动递增,location
),并且我有一个csv包含1列,看起来像:
I have a table in the database called locations
which contains 2 columns(id
which is auto incremented , location
) , And I have a csv contains 1 column looks like :
当我尝试将该文件导入到locations
表时,出现此错误invalid column count in CSV input on line 1
.
When I try to import that file to locations
table , I get this error invalid column count in CSV input on line 1
.
我也尝试过CSV using LOAD DATA
,但是我得到了:MySQL returned an empty result set (i.e. zero rows)
Also I tried CSV using LOAD DATA
but I get this : MySQL returned an empty result set (i.e. zero rows)
推荐答案
如果您的计算机支持Java,请使用以下解决方案
If Java is supported in your machine, Use below solution
https://dbisweb.wordpress.com/
要做的简单配置是
<?xml version="1.0" encoding="UTF-8"?>
<config>
<connections>
<jdbc name="mysql">
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/test1</url>
<user>root</user>
<password></password>
</jdbc>
</connections>
<component-flow>
<execute name="file2table" enabled="true">
<migrate>
<source>
<file delimiter="," header="false" path="D:/test_source.csv"/>
</source>
<destination>
<table connection="mysql">locations</table>
</destination>
<mapping>
<column source="1" destination="location" />
</mapping>
</migrate>
</execute>
</component-flow>
</config>
如果您有兴趣,可以通过Java代码实现.
If you are interested, Same can be achieved by Java code.
Source source = new File("D:/test_source.csv", ',', false);
Destination destination = new Table("locations", new JDBCConnection("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/test1", "root", ""));
List<Mapping> mapping = new ArrayList<>();
mapping.add(new Mapping("1", "location", null));
Component component = new MigrateExecutor(source, destination, mapping);
component.execute();
这篇关于导入csv文件时,mysql输入中的mysql无效列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!