mysqlとclsqlで文字化け その1

emacs/slimeから接続して結果を取得しても、shellからつないでも日本語が化ける。
char(10)なカラムに

"あいうえお"

をInsertすると結果は

"あいう■"

みたいにつぶれる。
char(12)だと

"あいうえ"

になったから、一文字3バイト??になってるのか??

わからんながらに色々調べる。
/etc/mysql/my.conf
の[mysqld]に

default-character-set = utf8

を追加。
それから[mysql]にも

default-character-set = utf8

を追加。
で一度停止。

$mysqladmin -u root -p shutdown

起動。

&mysqld_safe --user=mysql &

で、

show variables like 'char%';

してみるとこんな感じ。

mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       | 
| character_set_connection | utf8                       | 
| character_set_database   | latin1                     | 
| character_set_filesystem | binary                     | 
| character_set_results    | utf8                       | 
| character_set_server     | utf8                       | 
| character_set_system     | utf8                       | 
| character_sets_dir       | /usr/share/mysql/charsets/ | 
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

ほとんどutf8。これでいいのか??
まずshellからつないでみる。

$ mysql -u root -h localhost -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.38-Ubuntu_0ubuntu1-log Ubuntu 7.04 distribution

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

mysql> use test_schema
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> insert into tb0 values(1,"あいうえお","あいうえお");
Query OK, 1 row affected (0.00 sec)

mysql> select * from tb0;
+----+-----------------+-----------------+
| id | name            | comment         |
+----+-----------------+-----------------+
|  1 | あいうえお      | あいうえお      | 
+----+-----------------+-----------------+
1 row in set (0.00 sec)

おお。うまくいってんじゃん。
これでslimeからもうまくいけばOKだ。やってみる。

CL-USER> (clsql:query "select * from tb0")
((1 "?????" "?????"))
("id" "name" "comment")

ダメ。化けてます。
slime上からinsertするとどうだろう??

CL-USER>  (clsql:insert-records :into "tb0"
       :attributes '(id name comment)
       :values '(2 "あいうえお" "あいうえお"))
; No value
CL-USER> (clsql:query "select * from tb0")
((1 "?????" "?????") (2 "あいうえ" "あいうえ"))
("id" "name" "comment")

おお。slime上から入れると化けてない。
あ・・・。「あいうえ」だけで「お」がなくなってる。
nameとcommentはchar(12)だから一文字で3文字と思われているらしい。
ともかくこれではだめだ。

clsqlからつないだ時はlatin1になってるんでしょうか?
MyNAによるとこれをどうにかするには
キャラクターセットを mysql_options()で指定する or アプリがmy.cnf を読むようにする
libmysql.dll, libmysqlclientをコンパイルしなおして標準のキャラクタセットを変える
と書いてある。
http://www.mysql.gr.jp/frame/modules/bwiki/?FAQ#content_1_44

libmysqlclientのコンパイルなんてヤだし、commonlispからmysql_options呼ぶ方法なんてしらねーよ。
手詰まり・・・PostgreSQLにかえよかな・・・。