Friday, December 1, 2006

UTF-8 in mysql 5.0

To set the server default character set, use the --character-set-server=utf8 option. Or, put character-set-server=utf8 in the [mysqld] block of /etc/my.cnf.

To check what the character set variables are, do 'show variables' (in the mysql client) and look for variables starting with character_set.

To find out what character set a table's columns are using, do 'show full columns in my_table_name'. Look at the Collation column.

To convert all columns in a table to use utf8, do

ALTER TABLE my_table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

You can also export and re-import.