2008年9月7日星期日

The ultimate solution to MySQL chinese charset problem using ant sql task

This is the check list of items that need to be set to unicode:
1. The character encoding of SQL file for ant to call
2. The url attribute of ant task needs to be like this:
jdbc:mysql://localhost:3306/cocomoII?useUnicode=true&characterEncoding=UTF-8
3. The encoding attribute of ant task needs to be set to utf-8
4. Database and tables need to use utf-8 by adding CHARACTER SET utf8 COLLATE utf8_general_ci to the end of create database/table statement. The default is latin1!
5. (Optional)Start mysqld with --character-set-server=utf8 --collation-server=utf8_general_ci

Character encoding of mysql can be set in several levels, they are: server>database>table>column. If encoding at lower level is not specified, the one of higher one level is used.
The above 4 steps guarantee that the data would be correctly stored in database. If you want to view data correctly from mysql client, the additional steps are needed:

6. In mysql prompt:
mysql> charset utf8;

没有评论: