导入csv表时MySQL无效的UTF8字符串

MySQL Invalid UTF8 character string when importing csv table(导入csv表时MySQL无效的UTF8字符串)
本文介绍了导入csv表时MySQL无效的UTF8字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过以下方式将 .csv 文件导入 MySQL 数据库:

I want to import an .csv file into MySQL Database by:

load data local infile 'C:\Users\t_lichtenberger\Desktop\tblEnvironmentLog.csv'
into table tblenvironmentlog
character set utf8
fields terminated by ';'
lines terminated by '
'
ignore 1 lines;

.csv 文件如下所示:

The .csv file looks like:

但我收到以下错误,我无法解释原因:

But I am getting the following error and I cannot explain why:

Error Code: 1300. Invalid utf8 character string: 'M'

有什么建议吗?

推荐答案

查看导出的设置.寻找UTF-8".

See what the settings for the export were. Look for "UTF-8".

这个 表明截断文本"是由数据未编码为 utf8mb4 引起的.在 MySQL 之外,寻找UTF-8".(在 MySQL 内部,utf8 和 utf8mb4 对于所有欧洲字符集同样有效,因此 ü 应该不是问题.

如果导出为cp1252"(或多种编码中的任何一种),ü 的字节对于 utf8mb4 将无效,从而导致截断.

If it was exported as "cp1252" (or any of a number of encodings), the byte for ü would not be valid for utf8mb4, leading to truncation.

如果这个分析是正确的,有两种解决方案:

If this analysis is correct, there are two solutions:

A 计划:导出为 UTF-8.

计划 B:导入为 latin1.(您不需要更改列/表定义,只需更改LOAD DATA.)

Plan B: Import as latin1. (You do not need to change the column/table definition, just the LOAD DATA.)

这篇关于导入csv表时MySQL无效的UTF8字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)