How to correct double-encoded UTF-8 strings sitting in MySQL utf8_general_ci fields?

后端 未结 6 1543
感动是毒
感动是毒 2020-12-15 07:42

I have to redesign a class where (amongst other things) UTF-8 strings are double-encoded wrongly:

$string = iconv(\'ISO-8859-1\', \'UTF-8\', $string);
:
$str         


        
6条回答
  •  天涯浪人
    2020-12-15 08:42

    I found the following approach simpler:

    mysqldump -h DB_HOST -u DB_USER -p --skip-set-charset --default-character-set=latin1 DB_NAME > DB_NAME-dump.sql
    

    Then drop all tables and re-import with following command:

    mysql -h DB_HOST -u DB_USER -p --default-character-set=utf8 DB_NAME < DB_NAME-dump.sql
    

    Tip was found at this URL: http://blog.hno3.org/2010/04/22/fixing-double-encoded-utf-8-data-in-mysql/

提交回复
热议问题