JavaWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JavaWorld@TW » JDBC/SQL討論區 » MySQL  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 MySQL 無間中文 [討論版]
hkvip





發文: 53
積分: 1
於 2005-09-30 09:46 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
MySQL 無間中文, 討論版

原文章, 請參考:

http://www.javaworld.com.tw/jute/post/view?bid=21&id=128481&sty=1&tpg=1&age=0

大家請在這裡討論, 以保持原文章的簡潔. 謝謝. Big Smile


vote up 0 vote down
reply to postreply to post
萬物在跳扎扎,風在期待出發。
作者 Re:MySQL 無間中文 [討論版] [Re:hkvip]
hkvip





發文: 53
積分: 1
於 2005-10-08 19:40 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
MySQL 4.1 在 Windows platform 還沒研究出來, Cry 繼續努力...

解決問題的關鍵就在怎樣把 MySQL 預設的 Latin1 改為 utf-8. 在 Linux 下, 進了mysql後, 打入如下指令:

mysql> show variables;

還沒有修改 /etc/my.cnf 之前, 可以看到下面的設定:

1
2
3
4
5
6
7
8
9
10
11
12
...
| character_set_client            | latin1                                                    |
| character_set_connection        | latin1                                                    |
| character_set_database          | latin1                                                    |
| character_set_results           | latin1                                                    |
| character_set_server            | latin1                                                    |
| character_set_system            | utf8                                                      |
| character_sets_dir              | /usr/share/mysql/charsets/                                |
| collation_connection            | latin1_swedish_ci                                         |
| collation_database              | latin1_swedish_ci                                         |
| collation_server                | latin1_swedish_ci                                         |
...


加上指定 default charset 後, 就變成了這樣:

1
2
3
4
5
6
7
8
9
10
11
12
...
| character_set_client            | utf8                                                      |
| character_set_connection        | utf8                                                      |
| character_set_database          | utf8                                                      |
| character_set_results           | utf8                                                      |
| character_set_server            | utf8                                                      |
| character_set_system            | utf8                                                      |
| character_sets_dir              | /usr/share/mysql/charsets/                                |
| collation_connection            | utf8_general_ci                                           |
| collation_database              | utf8_general_ci                                           |
| collation_server                | utf8_general_ci                                           |
...


這樣就大功告成了, 所有新建立的資料庫或者資料表, 都可以吃 utf-8 的字串, 中文問題就解決了. 可是在 windows plafrom 下, 兩個 (client/server) 都已經設定好default charset 是 utf-8, 可是 show variables 的時候, 得到下面的結果:

1
2
3
4
5
6
7
8
9
10
11
12
...
| character_set_client            | latin1                                                      |
| character_set_connection        | latin1                                                      |
| character_set_database          | utf8                                                        |
| character_set_results           | latin1                                                      |
| character_set_server            | utf8                                                        |
| character_set_system            | utf8                                                        |
| character_sets_dir              | D:\Development\MySQL.com\mysql-4.1.14-win32\share\charsets/ |
| collation_connection            | latin1_swedish_ci                                           |
| collation_database              | utf8_general_ci                                             |
| collation_server                | utf8_general_ci                                             |
...


好像 [client] 裡的 default-character-set=utf8 沒被吃到的樣子... Dead

正在想辦法解決... ( reading the manual... )


vote up 0 vote down
hkvip edited on 2005-10-08 19:52
reply to postreply to post
萬物在跳扎扎,風在期待出發。
作者 Re:MySQL 無間中文 [討論版] [Re:hkvip]
hkvip





發文: 53
積分: 1
於 2005-10-08 21:29 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
哇咧,見鬼了...

Windows platform是居然吃的, 這裡只是顯示成 Latin1 了...

給 [mysqld] 與 [client] 加上 default-character-set=utf8
後, 試著 drop 掉了原來的table, 然後重新建:

mysql> create table user(name varchar(30));

然後

mysql> show create table user;

Ya... 居然出現了下面的字樣:

1
...DEFAULT CHARSET=utf8 


MySQL已經預設好是 utf-8 了, 嘗試跑 Test.java, OK... 終於解決了耶.

不過還是奇怪, 為甚麼 show variables 的時候, 得到的結果跟 linux 有所不同呢? 而且, 用mysqladmin variables的指令, 卻得到正確的結果喔... (跟 linux 一樣)

莫非有bug...???


vote up 0 vote down
reply to postreply to post
萬物在跳扎扎,風在期待出發。

» JavaWorld@TW »  JDBC/SQL討論區 » MySQL

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JavaWorld@TW


Powered by Powerful JuteForum® Version Jute 1.5.8
Copyright© 2002-2003 Rainman Zhu,Zua,Netboy,Scott. All Rights Reserved.