Ruby/MySQL で MySQL5.0 にアクセスする
Ruby で MySQL にアクセスするにあたり、Ruby/MySQL を利用したメモ。
・環境
サーバー:MySQL 5.0
クライアント:MySQL 4.0
・ソース
(snip) HOST = "foo" USER = "user" PASSWD = "passwd" DB = "hoge" PORT = "3306" (snip) begin my = Mysql::new(HOST, USER, PASSWD, DB, PORT) rescue Mysql::DatabaseError => e puts e.errstr rescue Exception => ex puts ex ensure (snip) end
・実行結果
Client does not support authentication protocol requested by server; consider upgrading MySQL client
MySQL :: MySQL 5.6 リファレンスマニュアル :: B.5.2.4 クライアントは認証プロトコルに対応できません
のとおり、サーバーとクライアントの MySQLバージョン差異が原因です。
また、Ruby/MySQL においてはそもそも MySQL4.1.x で利用できないとのこと。
ということで、公式サイトにおいてあるパッチを適用しました。
・パッチ適用
$ cd /home/user $ wget http://www.tmtm.org/ruby/mysql/ruby_mysql4.patch $ cd /usr/local/lib/ruby/1.8 $ sudo patch < /home/user/ruby_mysql4.patch can't find file to patch at input line 3 Perhaps you should have used the -p or --strip option? The text leading up to this was:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
--- mysql_org.rb 2005-04-03 20:59:15.830032000 +0900 |
+++ mysql4.rb 2005-04-03 21:20:39.696140800 +0900 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-