在 MySQL 中检测 utf8 损坏的字符 [英] Detecting utf8 broken characters in MySQL

查看:27
本文介绍了在 MySQL 中检测 utf8 损坏的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,其中有一堆散落在多个表中的损坏的 utf8 字符.字符列表不是很广泛 AFAIK (áéíúóÁÉÍÓÚÑñ)

I've got a database with a bunch of broken utf8 characters scattered across several tables. The list of characters isn't very extensive AFAIK (áéíúóÁÉÍÓÚÑñ)

修复给定的表非常简单

update orderItem set itemName=replace(itemName,'á','á');

但是我无法找到检测损坏字符的方法.如果我做类似的事情

But I can't get a way of detecting the broken characters. If I do something like

SELECT * FROM TABLE WHERE field LIKE "%Ã%";

由于排序规则 (Ã=a),我获得了几乎所有字段.到目前为止,所有损坏的字符都以Ã"开头.数据库是西班牙语的,所以不使用这个特定的字符

I get nearly all the fields because of the collation (Ã=a). All broken characters so far start with an "Ã". The database is in spanish so this particular character isn't used

到目前为止我得到的损坏字符列表是

The list of broken chars I've got so far is

á = á
é = é
í- = í
ó = ó
ñ = ñ
á = Á

知道如何使这个 SELECT 按预期工作吗?(二进制搜索或类似的东西)

Any idea of how to make this SELECT to work as intended? (a binary search or something like that)

推荐答案

另一种方法如何,即来回转换列以获得正确的字符集?您可以将其转换为二进制,然后转换为 utf-8,然后转换为 iso-8859-1 或您正在使用的任何其他内容.有关详细信息,请参阅手册.

How about a different approach, namely converting the column back and forth to get the correct character set? You can convert it to binary, then to utf-8 and then to iso-8859-1 or whatever else you're using. See the manual for the details.

这篇关于在 MySQL 中检测 utf8 损坏的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆