我原则上了解了如何将现有数据库从拉丁语转换为UTF8。我已经能够使用拥有的数据库成功地做到这一点。
现有数据在匈牙利语中。以前,数据库字段设置为Latin1_german1_ci。结果,单词以这种方式存储在数据库中:
mâria
,但在前端中正确显示为:
mária,
如果我现在将所有内容都转换为UTF-8,则可以按照所有新数据进行工作。但是现有数据未在数据库中转换,并且完全显示在数据库中的数据库中:
Mâria
对我来说很有意义,因为它是UTF8。但这当然不是我想要的。但是,如何将数据库中的所有现有数据首先转换为“Mária”?
I have understood in principle how to convert an existing database from latin to utf8. I have already been able to do this successfully with the database I have.
The existing data is in Hungarian. The database fields were previously set to latin1_german1_ci. As a result, words were stored in the database in this way:
Mária
but in the frontend correctly shown as:
Mária
If I now convert everything to utf-8, it works as it should for all new data. But the existing data was not converted in the database and is displayed in the frontend exactly as it is in the database:
Mária
Which makes sense to me because it is utf8. But it is not what I want of course. But how do I get all the existing data in the database to be converted to e.g. "Mária" in first place?
发布评论
评论(1)
这是一个“ mojibake”问题(
代替
Á
)参见至于“转换”,首先决定您拥有的情况,然后应用给定的
alter(s)
: http://mysql.rjweb.org/mmysql.rjweb/mmysql.org/doc.php/doc.php/charcollcollcoll uchcolluchcoll_fixes_for_various_various_cases正确的方法。但是,在将其应用于生产之前进行测试。做“错误”的改变会造成一团糟。
请提供
显示创建表
和的样本选择六角(Col),col ...
,以及用于提供Mojibake的查询。显示诸如'char%
'的变量;但是您不妨去使用UTF8MB4。
That's a "Mojibake" problem (
á
in place ofá
) See Trouble with UTF-8 characters; what I see is not what I storedAs for "converting", first decide which case you have, then apply the given
ALTER(s)
: http://mysql.rjweb.org/doc.php/charcoll#fixes_for_various_casesTentatively the 2-step ALTER may be the correct approach. However, test before applying it to production. Doing the 'wrong' Alter will leave quite a mess.
Please provide
SHOW CREATE TABLE
and a sample ofSELECT HEX(col), col...
, plus the query that was used to give the Mojibake. AndSHOW VARIABLES LIKE 'char%
';`Note: For Western European languages, either
utf8
orutf8mb4
would be sufficient. But you may as well go for utf8mb4.