Last week I upgraded my blog from wordpress 2.1 to 2.2. Because the new version of wordpress uses UTF8 charset, while the older version uses Latin1, all the Chinese characters turns to question marks. I use this script to fix it:
#!/bin/bash
tables=`mysql -u WORDPRESS_DATABASE_USER_NAME -pPassword WORDPRESS_DATABASE_NAME \
-e “show tables” | grep wp_`
for table in $tables;
do
echo “processing table $table …”
mysqldump -u WORDPRESS_DATABASE_USER_NAME -pPassword WORDPRESS_DATABASE_NAME –opt \
–default-character-set=latin1 –skip-set-charset $table > $table.conv.sql
sed -e ‘s/latin1/utf8/g’ -i $table.conv.sql
mysql -u WORDPRESS_DATABASE_USER_NAME -pPassword –default-character-set=utf8 \
WORDPRESS_DATABASE_NAME < $table.conv.sql
done
After running this script, make sure the wp-config.php file under the wordpress root directory has following lines:
define(‘DB_CHARSET’, ‘utf8′);
define(‘DB_COLLATE’, ”);