MySQL to pure utf-8 character set configuration

I’m programming a new version of my Japanese translator in the python Django framework as practice. Aside from some hard lessons, such as you cannot install a Python 2.5 x64 binary in Windows and expect the mod_python installer to work, the following was my next problem:

Had some trouble importing a file with Japanese in UTF-8 encoding into mySQL. The import would go fine, then would completely come out garbage on output. I eventually figured out what to do. Edit the my.cnf for the server, and use the following parameters:


[mysqld]
default-character-set=utf8
default-collation=utf8_general_ci
character-set-server=utf8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'

[mysql]
default-character-set=utf8

Now, if I did the following in mySQL:


mysql> SHOW VARIABLES LIKE 'char%';
+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | utf8                           |
| character_set_connection | utf8                           |
| character_set_filesystem | binary                         |
| character_set_results    | utf8                           |
| character_set_server     | utf8                           |
| character_set_system     | utf8                           |
| character_sets_dir       | C:xamppmysqlsharecharsets |
+--------------------------+--------------------------------+
8 rows in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'collation%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

If everything is utf8, then you are golden!

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s