Chat (Lingr.com)
Informaiton
Daily
Column
- MySQL日本語の旅(5/1)
- アクセス向上秘伝(5/9)
- 一風変ったHaskellλ門(6/13)
- SICP Answer Book (5/31) 問題3.26追加
Zope Solution
Extra
アーカイブ
OSS案内所
Site Info
関連リンク
今日から、5.0.12を使っています。
MySQLのマニュアル( 10.6. UTF8 for Metadata )を見ると、データベース名はメタデータであり、 メタデータはUTF8になっていると書かれている。
ということは、CREATE DATABASE のときに、 キャラクタセットに utf8 を指定すれば良いのかも知れない。 ということで、さっそく試してみよう。
shell$ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 to server version: 5.0.12-beta-debug-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> SET NAMES utf8; Query OK, 0 rows affected (0.00 sec) mysql> CREATE DATABASE 東京; Query OK, 1 row affected (0.04 sec) mysql> CREATE DATABASE 大阪; Query OK, 1 row affected (0.00 sec) mysql> CREATE DATABASE 倉敷; Query OK, 1 row affected (0.00 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | | 倉敷 | | 大阪 | | 東京 | +--------------------+ 6 rows in set (0.00 sec) mysql>
東京ができて、大阪ができて、倉敷(私の出身地)ができるのだから、 たぶん大丈夫ではないだろうか。
念のため、名古屋も確かめておこう。
mysql> CREATE DATABASE 名古屋; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??' at line 1 mysql>
名古屋は特殊な文化圏だから駄目なんだろうか。
mysql> CREATE DATABASE 横浜; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??' at line 1 mysql>
横浜も駄目ということは、これは重大だ。
どうもダメな場合がいっぱいありそうだ。 cp932で大丈夫だった名前、ダメだった名前を再確認してみよう。
mysql> CREATE DATABASE あいうえお; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1 mysql> CREATE DATABASE あ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1 mysql> CREATE DATABASE 長い名前は大丈夫か; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1 mysql> CREATE DATABASE 元帳; Query OK, 1 row affected (0.00 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | | 倉敷 | | 元帳 | | 大阪 | | 東京 | +--------------------+ 7 rows in set (0.01 sec) mysql>
今までと情况が違うようだ。 元帳はちゃんとできたようだが、 「あいうえお」、「あ」、「長い名前は大丈夫か」はダメになってしまった。
UTF8にしても、データベース名はダメだった
ということは、SET NAMES utf8 をしたにも拘らず、 UTF8と説明されているデータベース名が正常に作られなかったことになる。
データベース名に漢字を使うのは、やっぱりダメなのだろうか?
「元帳」データベースは作成できたようなので、確認のために SHOW で確認しておこう。
mysql> SHOW CREATE DATABASE 元帳; +----------+-------------------------------------------------------------------+ | Database | Create Database | +----------+-------------------------------------------------------------------+ | 元帳 | CREATE DATABASE `元帳` /*!40100 DEFAULT CHARACTER SET latin1 */ | +----------+-------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql>
何かやるべきことを見逃しているのかなぁ。
次へ:SHOW CREATE DATABASEの出力中の`は何だろう
フィードバック:
There is no comment.