mysql导入csv出现1356_mysql导入CSV文件时CSV输入中的无效列数

在尝试将只包含一个列的CSV文件导入到包含两个列(id和location)的数据库locations表时,遇到错误'invalid column count in CSV input on line 1'。尝试使用LOAD DATA也返回空结果。解决方案是使用Java代码,通过配置数据库连接(如jdbc:mysql://localhost:3306/test1,用户名root),利用MigrateExecutor类处理源文件和目标表之间的映射进行导入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

bd96500e110b49cbb3cd949968f18be7.png

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 :

9cf2b8a0afe2ed6df9dfb0720d94c424.png

When I try to import that file to locations table , I get this error invalid column count in CSV input on line 1.

Also I tried CSV using LOAD DATA but I get this : MySQL returned an empty result set (i.e. zero rows)

解决方案

If Java is supported in your machine, Use below solution

The simple configuration required to do is

com.mysql.jdbc.Driver

jdbc:mysql://localhost:3306/test1

root

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 = new ArrayList<>();

mapping.add(new Mapping("1", "location", null));

Component component = new MigrateExecutor(source, destination, mapping);

component.execute();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值