如何修复双重编码的 UTF8 字符(在 utf-8 表中)

How to fix double-encoded UTF8 characters (in an utf-8 table)(如何修复双重编码的 UTF8 字符(在 utf-8 表中))
本文介绍了如何修复双重编码的 UTF8 字符(在 utf-8 表中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前的 LOAD DATA INFILE 是在假设 CSV 文件是 latin1 编码的情况下运行的.在此导入过程中,多字节字符被解释为两个单个字符,然后(再次)使用 utf-8 进行编码.

A previous LOAD DATA INFILE was run under the assumption that the CSV file is latin1-encoded. During this import the multibyte characters were interpreted as two single character and then encoded using utf-8 (again).

这种双重编码产生了像ñ而不是ñ这样的异常.

This double-encoding created anomalies like ñ instead of ñ.

如何更正这些字符串?

推荐答案

下面的MySQL函数会在双重编码后返回正确的utf8字符串:

The following MySQL function will return the correct utf8 string after double-encoding:

CONVERT(CAST(CONVERT(field USING latin1) AS BINARY) USING utf8)

它可以与 UPDATE 语句一起使用以更正字段:

It can be used with an UPDATE statement to correct the fields:

UPDATE tablename SET
    field = CONVERT(CAST(CONVERT(field USING latin1) AS BINARY) USING utf8);

这篇关于如何修复双重编码的 UTF8 字符(在 utf-8 表中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

相关文档推荐

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:按日期将数量值拆分为多行)