phpMyAdminの文字化け
仮想鯖にMySqlでDB構築する際、ついでだからとphpMyAdminを入れるのだけれど、
マルチバイトが文字化けする。
いつもどおりグーグル大先生に聞いてみる。
色々検索した結果、
my.confをいじるだの、
[mysqld] character-set-server = utf8 collation-server = utf8_general_ci init-connect = SET NAMES utf8 default-character-set = utf8 skip-character-set-client-handshake [mysqldump] default-character-set = utf8 [mysql] default-character-set = utf8
config.inc.phpをいじるだの、
$cfg['DefaultCharset'] = 'utf-8';
phpMyAdmin上で文字コードをちゃんと設定するなど、色々書いてあったが、
それらを闇雲に、忠実に書き換えた上で、やはり化ける。
で、決定的になおった瞬間はやはりある。
既に一つのDB、一つのテーブルを作っていたのだが、フィールド毎にも文字コードの設定があるということをすっかり忘れていた。
我ながら詰めが甘い。
己の愚かさを嘆きつつ、地道に設定しなおす。
すると見事に、phpMyAdminからの日本語の挿入、表示が問題なくできるようになった。
Term上からも問題なく挿入と表示が出来たので、これで解決だろう。
しかし、はじめから全てのフィールドの文字コードを変えていれば、文字化けはなかったんだろうか。
その辺りの調査をめんどくさがってやらないのが、僕の詰めが甘い所以である。
そのかわりと言っては何だけどutf8_unicode_ciとutf8_general_ciの違いについて、
うちの最高技術責任者に聞いてみた。
曰く、
>A. あいまいな検索を許容するかしないかだったかな?
>Q. ちなみに、どっちが曖昧検索を許容するほう?
>A. unicodeだった気がするー
とのこと。
ついでなんでググってみる。
For any Unicode character set, operations performed using the _general_ci collation are faster than those for the _unicode_ci collation. For example, comparisons for the utf8_general_ci collation are faster, but slightly less correct, than comparisons for utf8_unicode_ci. The reason for this is that utf8_unicode_ci supports mappings such as expansions; that is, when one character compares as equal to combinations of other characters. For example, in German and some other languages “ß” is equal to “ss”. utf8_unicode_ci also supports contractions and ignorable characters. utf8_general_ci is a legacy collation that does not support expansions, contractions, or ignorable characters. It can make only one-to-one comparisons between characters.
参照 : http://dev.mysql.com/doc/refman/4.1/en/charset-unicode-sets.html
と、解りやすくかいてあった。
まぁ、聞く前にググれよって話だな。