Open Source WEB

再び、バイナリ版に戻る

さて、MySQL AB では、できるだけバイナリ版を使うようにということだったので、 ここから後は、再びバイナリ版での動作を書くことにする。

バイナリ版でも日本語は使えるのだが、デフォルトが英語(latin1)になっているので、 必要に応じてなんらかの方法でオプション指定が必要になる。


mysqlクライアントのデフォルトのキャラクタセット

復習になるが、標準のバイナリ版のサーバを普通に起動し、

# /usr/local/mysql/bin/mysqld_safe --user=mysql &

mysqlクライアントコマンドもオプションなしで起動した場合に、 キャラクタセット関連のシステム変数がどうなっているか、もう一度見てみよう。

$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.10-standard-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SHOW VARIABLES LIKE 'character\_set\_%';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| character_set_client     | latin1 |
| character_set_connection | latin1 |
| character_set_database   | latin1 |
| character_set_results    | latin1 |
| character_set_server     | latin1 |
| character_set_system     | utf8   |
+--------------------------+--------+
6 rows in set (0.05 sec)

mysql>

mysqlコマンドでデフォルトキャラクタセットを指定して起動

mysqlコマンドのオプション指定をどうやるかは、 他のコマンドでもだいたいそうなんだが、--helpオプションを 付加してヘルプを見ればよい。

$ mysql --help
mysql  Ver 14.7 Distrib 4.1.10, for pc-linux-gnu (i686)
Copyright (C) 2002 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --auto-rehash       Enable automatic rehashing. One doesn't need to use
                      'rehash' to get table and field completion, but startup
                      and reconnecting may take a longer time. Disable with
                      --disable-auto-rehash.
  -A, --no-auto-rehash
                      No automatic rehashing. One has to use 'rehash' to get
                      table and field completion. This gives a quicker start of
                      mysql and disables rehashing on reconnect. WARNING:
                      options deprecated; use --disable-auto-rehash instead.
  -B, --batch         Don't use history file. Disable interactive behavior.
                      (Enables --silent)
  --character-sets-dir=name
                      Directory where character sets are.
  --default-character-set=name
                      Set the default character set.
以下省略

これで、起動時にデフォルトのキャラクタセットを指定するには、

mysql --default-character-set=キャラクタセット

で良いことが分った。

では、さっそく実行してみよう。

$ mysql --default-character-set=ujis
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.10-standard-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SHOW VARIABLES LIKE 'character\_set\_%';
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| character_set_client     | ujis   |
| character_set_connection | ujis   |
| character_set_database   | latin1 |
| character_set_results    | ujis   |
| character_set_server     | latin1 |
| character_set_system     | utf8   |
+--------------------------+--------+
6 rows in set (0.00 sec)

mysql>

すると、

  • character_set_client
  • character_set_connection
  • character_set_results

の3つだけが、latin1 から ujis に変った。 どうも、この3つのシステム変数は、 mysqlのクライアントと関連するのではないだろうか。


戻る:5.0の新機能

次へ:my.cnfを使った起動オプション指定


フィードバック:

Name:
Comment:
yuka: (Fri Jun 3 17:15:37 2005 )
バージョンが3.0代のmysqlサーバだとキャラクターセットを変える方法はバージョン4.0代のものと一緒ですか?

このサイトは、 IPA の「平成15年度オープンソフトウエア活用基盤整備事業」 の委託事業として開発されたKahuaで試験的に運用しております。

Copyright (c) 2004-2007 株式会社タイムインターメディア About Us