MySQL Convert latin1 data to UTF8

前端 未结 7 1085
-上瘾入骨i
-上瘾入骨i 2020-12-03 02:30

I imported some data using LOAD DATA INFILE into a MySQL Database. The table itself and the columns are using the UTF8 character set, but the default character set of the d

7条回答
  •  被撕碎了的回忆
    2020-12-03 02:54

    I've had cases like this in old wordpress installations with the problem being that the data itself was already in UTF-8 within a Latin1 database (due to WP default charset). This means there was no real need for conversion of the data but the ddbb and table formats. In my experience things get messed up when doing the dump as I understand MySQL will use the client's default character set which in many cases is now UTF-8. Therefore making sure that exporting with the same coding of the data is very important. In case of Latin1 DDBB with UTF-8 coding:

    $ mysqldump –default-character-set=latin1 –databases wordpress > m.sql
    

    Then replace the Latin1 references within the exported dump before reimporting to a new database in UTF-8. Sort of:

    $ replace "CHARSET=latin1" "CHARSET=utf8" \
        "SET NAMES latin1" "SET NAMES utf8" < m.sql > m2.sql
    

    In my case this link was of great help. Commented here in spanish.

提交回复
热议问题