简体   繁体   English

将数据库数据转换为utf8-正确的方法是什么?

[英]Convert Database Data to utf8 - What is the correct way?

I have MYSQL database collation set to latin1_swedish_ci but my site uses encoding windows-1256 . 我将MYSQL数据库排序规则设置为latin1_swedish_ci但是我的站点使用windows-1256编码。 This means the data inside tables is encoded with windows-1256 . 这意味着表内的数据使用windows-1256编码。

What is the correct way to convert my database tables/fields and data to utf-8 using iconv or any other library? 使用iconv或任何其他库将数据库表/字段和数据转换为utf-8的正确方法是什么?

First, you need to verify that the data in the table(s) is really latin1. 首先,您需要验证表中的数据确实是latin1。 Could you do SELECT HEX(col), col ... to see what it looks like. 您可以SELECT HEX(col), col ...以查看其外观吗。

Depending on whether it is latin1 encoding or utf8 encoding (or something else) will determine what steps to perform. 根据是latin1编码还是utf8编码(或其他方式),将确定要执行的步骤。 (If you do these steps without knowing, you could make things worse.) (如果您在不知情的情况下执行这些步骤,可能会使情况变得更糟。)

These references give you the next steps: http://dev.mysql.com/doc/refman/5.0/en/alter-table.html and/or http://mysql.rjweb.org/doc.php/charcoll 这些参考为您提供了后续步骤: http : //dev.mysql.com/doc/refman/5.0/en/alter-table.html和/或http://mysql.rjweb.org/doc.php/charcoll

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM