mariadb “错误2013(HY000):在加载数据时执行查询”“时与MySQL服务器的连接丢失

gmol1639  于 2022-11-08  发布在  Mysql
关注(0)|答案(1)|浏览(315)

当我尝试使用load data命令将数据加载到MySQL(实际上是MariaDB)表中时,出现错误:

load data local infile '/tmp/my_data.tsv' 
into table my_schema.my_table
fields terminated by '\t' 
optionally enclosed by '"'
escaped by '\\'
lines terminated by '\n';

尝试给定的herehere解决方案不起作用。

w8biq8rn

w8biq8rn1#

由于某种原因,当您正在加载的数据违反了外键约束(在here中有更详细的描述)时,MySQL会给出这个模糊的错误消息。
我设法通过直接从命令行执行load data命令来获得正确的错误消息。* 即 * 运行:

mysql -u username -p --local-infile --execute= \
"load data local infile '/tmp/my_data.tsv' into table my_schema.my_table \
fields terminated by '\t' optionally enclosed by '\"' escaped by '\\\\';"

显示错误消息:

Cannot add or update a child row: a foreign key constraint fails 
(`my_schema`.`my_table`, CONSTRAINT `other_table` FOREIGN KEY
(`id`) REFERENCES `other_table` (`id`))

删除违反外键约束的行后,我可以导入数据。

相关问题