Set MySQL default character set as UTF8 on CentOS

The default character set of MySQL installed in CentOS 5 is latin while a feasible one for CJKs is UTF-8.

mysql> SHOW VARIABLES LIKE '%character%';
+--------------------------+--------+
| Variable_name | Value |
+--------------------------+--------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
+--------------------------+--------+

To enable whole system UTF-8, we need to add the following codes in /etc/my.cnf:
[client]
...
default-character-set = utf8

[mysqld]
...
character-set-server = utf8

mysql> SHOW VARIABLES LIKE '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

There are lots of additional settings in my Gentoo box, but it seems we don’t need right now. Maybe it can be use later. enjoyt it. 😉

UPDATE
[120302] The parameter default-character-set = utf8 for server configuration in 5.1.61 (or 5.1) is deprecated. We should use character-set-server = utf8 instead.

Leave a Reply

Your email address will not be published. Required fields are marked *