Home arrow Blog arrow Configuring MySQL for UTF-8

Configuring MySQL for UTF-8

If you want to run MySQL primarily using UTF-8 then the configuration file my.cnf should contain the following directives:

[client]
default-character-set=utf8

[mysqld]
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
default-character-set=utf8
character-set-server = utf8
collation-server = utf8_general_ci

[mysql]
default-character-set=utf8

Check that things look right by running this command or by using phpMyAdmin to look at the "Variables" for the server, or some similar technique.

show variables like 'char%';

which should give a result something like:

+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+

Then try:

show variables like 'col%';

which should give:

+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+

#128003 • 02/27/2011 5:11pm by Martin Brampton • Vote: Up votes (212) Down votes (125)