Koozali.org: home of the SME Server

Mysql character sets configuration

Offline cactus02

  • *
  • 24
  • +0/-0
Mysql character sets configuration
« on: October 23, 2009, 06:05:17 PM »
I want to change mySQL latin1 character set configuration to UTF8 by default !
Wordpress blog used UTF8 but mySQL is set to latin1.
This cause problems when restoring a backup. Accentuated characters gets messed up !
é becomes A°... Etc...
Is there a configuration file I can change ?
Thank you !

Offline mmccarn

  • *
  • 2,630
  • +10/-0
Re: Mysql character sets configuration
« Reply #1 on: October 25, 2009, 04:39:03 PM »
From this post: http://alexking.org/blog/2008/03/06/mysql-latin1-utf8-conversion, it looks like you need to:
 - dump your wordpress database
 - delete it
 - re-create it using the correct character set
 - reimport your data

(alternatively, it may be possible to dump your wordpress data, create a new database, then change your wordpress config to use the new database)

SME includes a script to dump all SQL databases: /etc/e-smith/events/actions/mysql-dump-tables, which places dumps of all databases in /home/e-smith/db/mysql


Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: Mysql character sets configuration
« Reply #2 on: October 25, 2009, 08:27:08 PM »
I suggest you do as mmccarn suggests as changing the default charachter set will undoubtedly influence webmail, which also uses MySQL.

The easiest solution is to do something like this:
Code: [Select]
mysqldump --opt --database databasename > /tmp/wordpress-org.sql
sed -e 's/SET NAMES utf8/SET NAMES latin1/' /tmp/wordpress-org.sql > /tmp/wordpress-new.sql
mysqladmin drop databasename
mysqladmin create databasename
mysql -e 'ALTER DATABASE databasename DEFAULT CHARACTER SET latin1'
mysql databasename < /tmp/wordpress-new.sql

Make sure to replace every occurence of databasename with the correct name of your database.
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)