MySql 5 basic handling of utf-8 database

1. Setup default mysql character set
modify mysql.cnf
[client]
default_character_set=utf8
[mysqld]
default-character-set=utf8
character-set-server = utf8
collation-server = utf8_general_ci
[mysql]
default_character_set=utf8

You will need to setup apache too if your website need utf-8
modify \apache\conf\extra\httpd-languages.conf
find :
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw
add :
AddLanguage UTF-8 .utf8
find :
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
change :
LanguagePriority UTF-8 en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
add :
DefaultLanguage UTF-8
AddDefaultCharSet UTF-8

2. Check database character set
mysql>SHOW VARIABLES LIKE ‘character_set%’;
mysql>SHOW VARIABLES LIKE ‘collation%’;
Change database character set
mysql>SET NAMES utf8;
mysql>SET CHARACTER SET utf8;
mysql>SET GLOBAL/SESSION character_set_XXX=utf8

3. Create utf-8 database
mysql>create database db_name character set utf8;

4. Restore utf-8 dump
mysql -uroot dbname < dump.sql –default-character-set=utf8

Remark: please note that mysql start supporting utf-8 from 5.0

Netbeans project with UTF-8

基本上,NetBeans預設的file encoding是系統語系,所以在繁中版Windows是MS950,遇到”堃”、”綉”等字時會發生錯誤。鳥毅這幾年都用UTF-8編碼,必須手動改 Tools->Options->Advanced Options->Editing->Java Sources->Default EncodingUTF-8。但這樣編譯時會錯,因此還得改Project的Properties->Build->Compiling->Additional Compiler Options加上 -encoding UTF-8

來源鳥毅的Blog