Forum: Ruby on Rails MySQL Adapter on Rails 2.2

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joshua P. (Guest)
on 2008-12-02 14:51
(Received via mailing list)
Hi all,

I've been searching through the list about configuring MySQL adapter
on Rails 2.2, and it seems that this question is asked over and over
again without any solution :-D Why did Rails 2.2 made configuring the
mysql driver so difficult? Why is it a move backward in Rails 2.2? Why
isn't there any documentation on this at all while people keep asking
this same question over and over again?

Cheers.

--
Not by might nor by power, but by His Spirit.

Read my blog: http://joshuajava.wordpress.com/
Follow me on twitter: http://twitter.com/jpartogi
Frederick C. (Guest)
on 2008-12-02 15:05
(Received via mailing list)
On Dec 2, 12:50 pm, "Joshua P." <removed_email_address@domain.invalid> wrote:
> Hi all,
>
> I've been searching through the list about configuring MySQL adapter
> on Rails 2.2, and it seems that this question is asked over and over
> again without any solution :-D Why did Rails 2.2 made configuring the
> mysql driver so difficult? Why is it a move backward in Rails 2.2? Why
> isn't there any documentation on this at all while people keep asking
> this same question over and over again?

Are you talking about the removal of the pure ruby driver ?
I haven't moved most of the stuff I do to rails 2.2, but creating a
rails 2.2 app from scratch basically just worked in the same way as it
has ever done. (or are you talking about the change from mysql as a
default to sqlite3 ?)

Fred
Joshua P. (Guest)
on 2008-12-02 23:38
(Received via mailing list)
I was talking about the mysql ruby driver is not come bundled and
installing it manually is not easy too.

On Dec 3, 12:04 am, Frederick C. <removed_email_address@domain.invalid>
Rick (Guest)
on 2008-12-03 04:21
(Received via mailing list)
Hey Joshua and Fred,

I agree with the general statement that installing the mysql gem has
gotten harder.  In fact, the only way I've been able to do it is by
pulling in the mysql-ruby source from tmtm.org, modifying the
extconf.rb file, and building my own gemspec.

I have been able to install versions from 2.7.0 through 2.8 on Mac OS
X under Ruby 1.8.7p72, Rails 2.2.2, Gem 1.3.1.  I don't have access to
a Windows system of any kind however so I don't know how portable my
change is.

Rick
Frederick C. (Guest)
on 2008-12-03 10:24
(Received via mailing list)
On Dec 3, 2:20 am, Rick <removed_email_address@domain.invalid> wrote:
> change is.
>

If you're dealing with the gem that is nothing to do with the rails
version. The ruby version might have an impact though (I've been
staying away from 1.8.7).
Personally with ruby 1.8.6 I've had zero problems. It's a  bit of a
coincidence timing wise but over the past week I've setup/helped setup
3 machines for our developers (2 macs, one ubuntu) and they've all
gone swimmingly

Fred
Rick (Guest)
on 2008-12-03 10:34
(Received via mailing list)
Fred,

I'll give 1.8.6 a try and let you know what happens, 1.8.6p114 is what
ships on the Mac.

Rick

On Dec 2, 11:24 pm, Frederick C. <removed_email_address@domain.invalid>
Rick (Guest)
on 2008-12-03 11:24
(Received via mailing list)
Well, that didn't seem to go too well.  It seems that somewhere in the
mkmf / extconf.rb soup the actual location of the mysql home has
gotten lost.  The only way this will work is if mysql is installed in /
usr/local, the default for the distributed precompiled version is to
go in /usr/local/mysql.


$ which ruby
/usr/bin/ruby
$ ruby --version
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
$ which rails
/usr/bin/rails
$ rails --version
Rails 2.2.2
$ which gem
/usr/bin/gem
$ gem --version
1.3.0
$ which mysql
/usr/local/mysql/bin/mysql
$ mysql --version
mysql  Ver 14.12 Distrib 5.0.51a, for apple-darwin8.6.0 (powerpc)
using readline 5.0
$ gem list mysql

*** LOCAL GEMS ***


$ sudo env ARCHFLAGS="" gem install mysql
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
  ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
  --with-opt-dir
  --without-opt-dir
  --with-opt-include
  --without-opt-include=${opt-dir}/include
  --with-opt-lib
  --without-opt-lib=${opt-dir}/lib
  --with-make-prog
  --without-make-prog
  --srcdir=.
  --curdir
  --ruby=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/
ruby
  --with-mysql-config
  --without-mysql-config
  --with-mysql-dir
  --without-mysql-dir
  --with-mysql-include
  --without-mysql-include=${mysql-dir}/include
  --with-mysql-lib
  --without-mysql-lib=${mysql-dir}/lib
  --with-mysqlclientlib
  --without-mysqlclientlib
  --with-mlib
  --without-mlib
  --with-mysqlclientlib
  --without-mysqlclientlib
  --with-zlib
  --without-zlib
  --with-mysqlclientlib
  --without-mysqlclientlib
  --with-socketlib
  --without-socketlib
  --with-mysqlclientlib
  --without-mysqlclientlib
  --with-nsllib
  --without-nsllib
  --with-mysqlclientlib
  --without-mysqlclientlib


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/
mysql-2.7 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql-2.7/gem_make.out
$

I haven't figured out how to pass "--with-mysql-dir" or any of the
other extconf.rb variants in on the command line so here's what I did.

1) Download the source from tmtm.org
2) Modify extconf.rb such that for line 15:
WAS:    inc, lib = dir_config('mysql', '/usr/local')
IS:         inc, lib = dir_config('mysql', '/usr/local/mysql')
3) Create  a mysql.gemspec thus:
#################
require 'rubygems'
require 'rake'

version = Dir.pwd.split(pattern="-").last

spec = Gem::Specification.new do |s|
  s.name = "mysql"
  s.version = "#{version}"
  s.email = "removed_email_address@domain.invalid"
  s.homepage = "http://www.tmtm.org/en/mysql/ruby/"
  s.platform = Gem::Platform::RUBY
  s.summary = "MySQL/Ruby provides the same functions for Ruby
programs that the MySQL C API provides for C programs."
  s.files = FileList['[A-Za-z]*'].to_a
  s.extensions = ["./extconf.rb"]
end

if $0 == __FILE__
  Gem::Builder.new(spec).build
end
#################

$ ruby --version
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
$ ruby mysql.gemspec
WARNING:  no author specified
WARNING:  no rubyforge_project specified
WARNING:  RDoc will not be generated (has_rdoc == false)
  Successfully built RubyGem
  Name: mysql
  Version: 2.8
  File: mysql-2.8.gem
$ gem --version
1.3.0
$ gem list mysql --local

*** LOCAL GEMS ***


$ sudo env ARCHFLAGS="" gem install mysql
Password:
Building native extensions.  This could take a while...
Successfully installed mysql-2.8
1 gem installed
$ gem list mysql --local

*** LOCAL GEMS ***

mysql (2.8)
$ cd /Library/Ruby/Gems/1.8/gems/mysql-2.8

$ ruby test.rb -- localhost rick tu44stu44 test222mysql_test
Loaded suite test
Started
...................................................................................................................
Finished in 3.697758 seconds.

115 tests, 391 assertions, 0 failures, 0 errors
$

so what do you think about that?
Rick

On Dec 2, 11:24 pm, Frederick C. <removed_email_address@domain.invalid>
Frederick C. (Guest)
on 2008-12-03 11:26
(Received via mailing list)
On Dec 3, 9:23 am, Rick <removed_email_address@domain.invalid> wrote:
> Well, that didn't seem to go too well.  It seems that somewhere in the
> mkmf / extconf.rb soup the actual location of the mysql home has
> gotten lost.  The only way this will work is if mysql is installed in /
> usr/local, the default for the distributed precompiled version is to
> go in /usr/local/mysql.

> so what do you think about that?

Since day one i've always done

gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/
mysql_config

Fred
Rick (Guest)
on 2008-12-03 11:32
(Received via mailing list)
So what little genie whispered that magic into your ear?
Thanks for passing it on though.  I don't want to say how long I spent
puzzling through the mkmf / extconf code trying to figure how to pass
that sucker in.  Is this a general RoR convention or what?

Rick

On Dec 3, 12:25 am, Frederick C. <removed_email_address@domain.invalid>
Frederick C. (Guest)
on 2008-12-04 11:27
(Received via mailing list)
On Dec 3, 9:32 am, Rick <removed_email_address@domain.invalid> wrote:
> So what little genie whispered that magic into your ear?
> Thanks for passing it on though.  I don't want to say how long I spent
> puzzling through the mkmf / extconf code trying to figure how to pass
> that sucker in.  Is this a general RoR convention or what?
>

This is just how rubygems works. Probably first read it via the
hivelogic install instructions for rails (http://danbenjamin.com/
articles/2007/02/ruby-rails-mongrel-mysql-osx)

Fred
Frederick C. (Guest)
on 2008-12-04 11:27
(Received via mailing list)
On Dec 4, 9:26 am, Frederick C. <removed_email_address@domain.invalid>
wrote:
>
Oops, one I first used must have been
http://danbenjamin.com/articles/2005/12/ruby_rails...
but the other one basically covers the same stuff.

Fred
Nellboy (Guest)
on 2008-12-04 13:38
(Received via mailing list)
Those Dan Benjamin articles are fantastic for OS X

I've also found the following to be very useful in ubuntu for RoR in
general: https://help.ubuntu.com/community/RubyOnRails

On Dec 4, 9:27 am, Frederick C. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.