Convert WordPress database from Latin1 to UTF-8

January 12, 2008 5:39 pm | In Tech | 2 Comments | hide

Some early WordPress databases use raw Latin1 encoding to represent UTF-8 characters. The following seems to be an O.K. way to convert those databases to native UTF-8 databases (at least it works for me, Mysql 5.0.45):

  1. Stop/restrict web service.
  2. Dump the database:
    $ mysqldump --default-character-set=latin1 --databases wordpress > m.sql
  3. Change encoding settings in m.sql, including table default encoding and client communication encoding:
    $ replace "CHARSET=latin1" "CHARSET=utf8" \
        "SET NAMES latin1" "SET NAMES utf8" < m.sql > m2.sql
  4. Import the “converted” sql:
    $ mysql < m2.sql
  5. Add the following lines to WordPress wp-config.php
    define('DB_CHARSET', 'utf8');
    define('DB_COLLATE', '');
  6. Reopen web service. That’s it.

Note: For future convenience, you might as well change the database default encoding to utf8.

Ref to WordPress documentation for details: here and here.

Tags: , , , ,

This weblog is licensed under a Creative Commons License.
Powered by WordPress. Theme based on Pool by Borja Fernandez.