Convert WordPress database from Latin1 to UTF-8
January 12, 2008 5:39 pm GMT-0700 | In TechSome 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):
- Stop/restrict web service.
- Dump the database:
$ mysqldump --default-character-set=latin1 --databases wordpress > m.sql
- 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
- Import the “converted” sql:
$ mysql < m2.sql
- Add the following lines to WordPress wp-config.php
define('DB_CHARSET', 'utf8'); define('DB_COLLATE', '');
- Reopen web service. That’s it.
Note: For future convenience, you might as well change the database default encoding to utf8.
3 Comments »
RSS feed for comments on this post.
Leave a comment
This weblog is licensed under a Creative Commons License.
Powered by WordPress. Theme based on Pool by Borja Fernandez.
Lord of wordpress!!!!!
Comment by kxn — January 12, 2008 10:17 pm GMT-0700 #
要命,前两天转trac DB,我怎么没想到 replace …
Orz
Comment by hutuworm — January 16, 2008 10:25 pm GMT-0700 #
Hi, I would extremely like to use your work,
but unfortunately, I got this message:
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘$ replace “CHARSET=latin1” “CHARSET=utf8” \
“SET NAMES latin1” “SET NAMES u’ at line 1
it might be really simple – but I do not know about it..
Comment by csaba — April 13, 2009 2:27 pm GMT-0700 #