MySQL Adapter on Rails 2.2

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 :smiley: 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.

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 :smiley: 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

I was talking about the mysql ruby driver is not come bundled and installing it manually is not easy too.

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

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.

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

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

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:

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

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

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

> 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)

Oops, one I first used must have been http://danbenjamin.com/articles/2005/12/ruby_rails_lighttpd_mysql_tiger but the other one basically covers the same stuff.

Fred

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: RubyOnRails - Community Help Wiki