UJP - 技術情報

Life is fun and easy!

不正IP報告数

Okan Sensor
 
メイン
ログイン
ブログ カテゴリ一覧

     

MySQLの言語セットを変更する

MySQLの言語セットを変更する


0.改訂履歴

  • 2005.06.15 新規作成

1.はじめに

 このドキュメントでは,MySQLの言語環境を変更する手順を説明する.

 なお,使用しているMySQLは,MacOS X 10.4上で稼働しているMySQL 4.1である.

2.現状確認

  • mysqlコマンドで接続し,キャラクタセットを確認する.
ivory:/usr/local/mysql/bin shinnai$ ./mysql -u root -p
Enter password:■■■■■
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.12-max

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

mysql>
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.09 sec)

mysql>
  • 言語は,latain1になっている.
  • systemではutf8と表示されているので,内部的にはユニコードで格納か?
  • デフォルトの言語セットを変更する為に,設定ファイルを変更する.
  • しかし,インストール後何もしてない状態では,デフォルトで稼働しているので,テンプレートから複写して使う.
  • 設定ファイルのテンプレートを確認する.
ivory:~ root# cd /usr/local/mysql
ivory:/usr/local/mysql root# ls -la
total 96
drwxr-xr-x   19 root   wheel    646 May 11 06:32 .
drwxr-xr-x    7 root   wheel    238 May 30 11:47 ..
-rw-r--r--    1 root   wheel  19071 May 11 05:57 COPYING
-rw-r--r--    1 root   wheel   5164 May 11 06:14 EXCEPTIONS-CLIENT
-rw-r--r--    1 root   wheel   8338 May 11 06:14 INSTALL-BINARY
-rw-r--r--    1 root   wheel   1937 May 11 05:57 README
drwxr-xr-x   69 root   wheel   2346 May 11 06:32 bin
-rwxr-xr-x    1 root   wheel    801 May 11 06:32 configure
drwxr-x---   10 mysql  wheel    340 Jun  2 14:35 data
drwxr-xr-x    5 root   wheel    170 May 11 06:32 docs
drwxr-xr-x   62 root   wheel   2108 May 11 06:32 include
drwxr-xr-x   12 root   wheel    408 May 11 06:32 lib
drwxr-xr-x    3 root   wheel    102 May 11 06:32 man
drwxr-xr-x   13 root   wheel    442 May 11 06:32 mysql-test
drwxr-xr-x    3 root   wheel    102 May 11 06:32 scripts
drwxr-xr-x    5 root   wheel    170 May 11 06:32 share
drwxr-xr-x   31 root   wheel   1054 May 11 06:32 sql-bench
drwxr-xr-x   14 root   wheel    476 May 11 06:32 support-files
drwxr-xr-x   21 root   wheel    714 May 11 06:32 tests
ivory:/usr/local/mysql root#
  • このサポートファイルの下を確認する.
ivory:/usr/local/mysql root# cd support-files
ivory:/usr/local/mysql/support-files root# ls -la
total 280
drwxr-xr-x   14 root  wheel    476 May 11 06:32 .
drwxr-xr-x   19 root  wheel    646 May 11 06:32 ..
-rw-r--r--    1 root  wheel   3069 May 11 06:32 MySQL-shared-compat.spec
-rw-r--r--    1 root  wheel    773 May 11 05:57 magic
-rw-r--r--    1 root  wheel   4908 May 11 06:32 my-huge.cnf
-rw-r--r--    1 root  wheel  20895 May 11 06:32 my-innodb-heavy-4G.cnf
-rw-r--r--    1 root  wheel   4884 May 11 06:32 my-large.cnf
-rw-r--r--    1 root  wheel   4896 May 11 06:32 my-medium.cnf
-rw-r--r--    1 root  wheel   2476 May 11 06:32 my-small.cnf
-rwxr-xr-x    1 root  wheel  30537 May 11 06:32 mysql-4.1.12.spec
-rwxr-xr-x    1 root  wheel    839 May 11 06:32 mysql-log-rotate
-rwxr-xr-x    1 root  wheel   6344 May 11 06:32 mysql.server
-rw-r--r--    1 root  wheel  30537 May 11 06:32 mysql.spec
-rw-r--r--    1 root  wheel    589 May 11 06:32 ndb-config-2-node.ini
ivory:/usr/local/mysql/support-files root# 
  • このcnfファイルがテンプレート.
  • 実験用なので,名前からして小さい構成と思われるテンプレートファイルを,/etc配下に複写する.
ivory:/usr/local/mysql/support-files root# cp my-small.cnf /etc/my.cnf
ivory:/usr/local/mysql/support-files root# 
  • このファイルの中身を見てみる.
71 max_allowed_packet = 16M
72 
73 [mysql]
74 no-auto-rehash
75 # Remove the next comment character if you are not familiar with SQL
76 #safe-updates
77 
78 [isamchk] 
  • [mysql]セクションに,次のように追加する.
71 max_allowed_packet = 16M
72  
73 [mysql]
74 no-auto-rehash
75 # Remove the next comment character if you are not familiar with SQL
76 #safe-updates
77 default-character-set=ujis
78 
79 [isamchk]                   
  • ujisとなっているのは,EUCであり,SJISの時はsjisと設定する
  • 設定ファイルを編集後,再度mysqlで接続してみる.
  • この時,データベースプロセスの再起動は不要である.
mysql> quit
Bye
ivory:/usr/local/mysql/bin shinnai$ ./mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 4.1.12-max

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    | sjis   |
| character_set_server     | latin1 |
| character_set_system     | utf8   |
+--------------------------+--------+
6 rows in set (0.00 sec)

mysql>  
  • OracleとかSybaseでは,内部格納の文字コードは,create database以前に変更が必要だが,あまり調べていないが,どうもMySQLはコンパイルの際に指定するようだ.


広告スペース
Google