続々Railsでデモを作れぇ! (T-T)

さてと、とりあえずCentOS4.4でRails2.0での動作は確認できたけど、
元々のcastleの環境をどうにかしたい。

/usr/local/lib/ruby/gems/1.8/gems/mysql-2.7配下でmysql.soをビルドし直すと、

ruby extconf.rb --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql
checking for main() in -lmysqlclient... no
checking for mysql_ssl_set()... no
checking for mysql.h... yes
creating Makefile
[root@castor mysql-2.7]# make
gcc -I. -I. -I/usr/local/lib/ruby/1.8/x86_64-linux -I. -DHAVE_MYSQL_H -I/usr/include/mysql -I/usr/local/include  -fPIC -g -O2  -c mysql.c
gcc -shared  -L'/usr/lib/mysql' -Wl,-R'/usr/lib/mysql' -L'/usr/local/lib' -Wl,-R'/usr/local/lib' -L'/usr/local/lib' -Wl,-R'/usr/local/lib' -o mysql.so mysql.o  -ldl -lcrypt -lm   -lc
[root@castor mysql-2.7]# ruby ./test.rb localhost root castle accident_test
ruby: symbol lookup error: ./mysql.so: undefined symbol: mysql_get_client_version

mysql.hにはちゃんとmysql_get_client_versionの定義はある(コンパイル出来ているんだから当然)
rpm -qi mysqlとすると、

]# rpm -qi mysql
Name        : mysql                        Relocations: (not relocatable)
Version     : 4.1.20                            Vendor: CentOS
Release     : 2.RHEL4.1.0.1                 Build Date: 2007年08月31日 10時52分49秒
Install Date: 2007年12月05日 13時53分03秒      Build Host: builder6
Group       : Applications/Databases        Source RPM: mysql-4.1.20-2.RHEL4.1.0.1.src.rpm
Size        : 5776939                          License: GPL
Signature   : DSA/SHA1, 2007年09月01日 09時18分23秒, Key ID a53d0bab443e1821
URL         : http://www.mysql.com
Summary     : MySQL client programs and shared libraries.
Description :
MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. The base package
contains the MySQL client programs, the client shared libraries, and
generic MySQL files.
Name        : mysql                        Relocations: (not relocatable)
Version     : 4.1.20                            Vendor: CentOS
Release     : 2.RHEL4.1.0.1                 Build Date: 2007年08月31日 11時14分14秒
Install Date: 2007年12月05日 13時53分57秒      Build Host: builder4.centos.org
Group       : Applications/Databases        Source RPM: mysql-4.1.20-2.RHEL4.1.0.1.src.rpm
Size        : 5490613                          License: GPL
Signature   : DSA/SHA1, 2007年09月01日 09時18分21秒, Key ID a53d0bab443e1821
URL         : http://www.mysql.com
Summary     : MySQL client programs and shared libraries.
Description :
MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. The base package
contains the MySQL client programs, the client shared libraries, and
generic MySQL files.

と2つ表示されちゃう。

# locate libmysqlclient.so
/usr/lib/mysql/libmysqlclient.so.14
/usr/lib/mysql/libmysqlclient.so.14.0.0
/usr/lib64/mysql/libmysqlclient.so.10
/usr/lib64/mysql/libmysqlclient.so.14
/usr/lib64/mysql/libmysqlclient.so.10.0.0
/usr/lib64/mysql/libmysqlclient.so
/usr/lib64/mysql/libmysqlclient.so.14.0.0

で見ると、そうかぁ64bit版もあるからなのねぇ

とりあえずyummysql関連を一旦削除

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Removing:
 mysql                   i386       4.1.20-2.RHEL4.1.0.1  installed         5.2 M
 mysql                   x86_64     4.1.20-2.RHEL4.1.0.1  installed         5.5 M
Removing for dependencies:
 mysql-devel             x86_64     4.1.20-2.RHEL4.1.0.1  installed         5.8 M
 mysql-server            x86_64     4.1.20-2.RHEL4.1.0.1  installed          23 M
 perl-DBD-MySQL          x86_64     2.9004-3.1.centos4  installed         238 k
 php-mysql               x86_64     4.3.9-3.22.9     installed          49 k

改めてインストール

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 mysql                   x86_64     4.1.20-3.RHEL4.1.el4_6.1  update            2.9 M
 mysql                   i386       4.1.20-3.RHEL4.1.el4_6.1  update            2.9 M
 mysql-devel             x86_64     4.1.20-3.RHEL4.1.el4_6.1  update            2.2 M
 mysql-server            x86_64     4.1.20-3.RHEL4.1.el4_6.1  update             10 M
 perl-DBD-MySQL          x86_64     2.9004-3.1.centos4  base              112 k
 php-mysql               x86_64     4.3.9-3.22.9     base               38 k

Transaction Summary
=============================================================================

ちょこっとバージョンが上がった?
で、

# ruby extconf.rb --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib64/mysql
# make
# ruby ./test.rb   (勝手にrootでアクセスするので、一旦rootのパスワードを無しとして)
Loaded suite ./test
Started
..................................................................F.........F...F.....F.......................
Finished in 0.128765 seconds.

  1) Failure:
test_fetch_double(TC_MysqlStmt2) [./test.rb:860]:
<-1.79769313486232e+308> expected but was
<-1.79769313486232e+308>.

  2) Failure:
test_fetch_mediumint(TC_MysqlStmt2) [./test.rb:734]:
<[-1]> expected but was
<[4294967295]>.

  3) Failure:
test_fetch_smallint(TC_MysqlStmt2) [./test.rb:703]:
<[-1]> expected but was
<[4294967295]>.

  4) Failure:
test_fetch_tinyint(TC_MysqlStmt2) [./test.rb:672]:
<[-1]> expected but was
<[4294967295]>.

110 tests, 339 assertions, 4 failures, 0 errors

で、何だかFailureになっているがmysqlにはアクセスできているようなので、とりあえずOK?

$ rake db:migrate
(in /home/kkijiya/RailsTest/accident)
== CreateReports: migrating ===================================================
-- create_table(:reports)
   -> 0.2020s
== CreateReports: migrated (0.2021s) ==========================================

うん、何とかテーブルは出来たみたい。

$ ruby script/generate scaffold Report
      exists  app/controllers/
      exists  app/helpers/
      create  app/views/reports
      exists  test/functional/
  dependency  model
      exists    app/models/
      exists    test/unit/
      exists    test/fixtures/
   identical    app/models/report.rb
   identical    test/unit/report_test.rb
   identical    test/fixtures/reports.yml
      create  app/views/reports/_form.rhtml
      create  app/views/reports/list.rhtml
      create  app/views/reports/show.rhtml
      create  app/views/reports/new.rhtml
      create  app/views/reports/edit.rhtml
      create  app/controllers/reports_controller.rb
      create  test/functional/reports_controller_test.rb
      create  app/helpers/reports_helper.rb
      create  app/views/layouts/reports.rhtml
      create  public/stylesheets/scaffold.css

WEBrickを起動して内容を確認。OKみたいだね。
ということで、結局は、mysqlのlibパスが/usr/lib/mysqlではなくて、/usr/lib64/mysqlが正解だったんじゃないか?(パッケージを入れ替えたのが良かったのかもしれないけど)