Rails 2.2.2, Mac OS X and MySQL

Hi all,

I hope someone can inform me on this. I was shocked to find that since
upgrading to Rails 2.2.2 my Rails projects using MySQL have broken.

I have read some webpages that talk about checking whether you have
libmysqlclient installed (without saying how one might check that!)
and moving MySQL from 64-bit to 32-bit installation (again, there is
no indication of how one does this). This is in Mac OS X 10.5.6.

I would really rather not mess about unduly with my MySQL
installation, since I use it for other purposes. So is there a simple
way for me to “downgrade” my Rails installation to one that does play
nicely with MySQL (and which one is that, BTW)?

Thanks,

Ian.

Ian P. wrote:

Hi all,

I hope someone can inform me on this. I was shocked to find that since
upgrading to Rails 2.2.2 my Rails projects using MySQL have broken.

Can you define “broken?” Are you getting errors? If so what are they?
What version of mysql do you have installed? I’m guessing it was working
just before you upgraded to Rails 2.2.2, but was there anything else
that you upgraded in the process? What version of Rails were you running
before you upgraded to Rails 2.2.2? Did you install a new mysql gem for
instance do you you have it installed at all?

I had issues with mysql, but it didn’t take much Googling to find a fix.
So I know for certain that Rails 2.2.2 will work just fine with MySQL,
as long as you have everything setup correctly. Chances are that if
you’re having trouble then others have had it already and posted the fix
on their blog.

If you really do end up needing to downgrade, then I would assume
uninstalling the Rails 2.2.2 gems should do the trick.

[sudo] gem uninstall rails --version 2.2.2
[sudo] gem uninstall actionmailer --version 2.2.2
[sudo] gem uninstall actionpack --version 2.2.2

On Mon, Mar 2, 2009 at 6:37 AM, Robert W. <
[email protected]> wrote:

that you upgraded in the process? What version of Rails were you running
uninstalling the Rails 2.2.2 gems should do the trick.

[sudo] gem uninstall rails --version 2.2.2
[sudo] gem uninstall actionmailer --version 2.2.2
[sudo] gem uninstall actionpack --version 2.2.2

Hi, one should also be able to install the previous (i.e. 2.1.x) and
update
the environment.rb to use it.
Again, I’m in agreement with the previous post of determining what are
the
exact nature of the issues
that you’re receiving and the relevant version information. How did you
install MySQL?

Good luck,

-Conrad

On Mon, Mar 2, 2009 at 7:12 AM, Ian P. [email protected] wrote:

Is there a page somewhere (I looked but couldn’t find one) that sets
Please install the mysql gem and try again: gem install mysql.

checking for main() in -lm… yes
details. You may need configuration options.
–srcdir=.
–with-mysql-lib
–without-mysqlclientlib
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/

as long as you have everything setup correctly. Chances are that if
uninstalling the Rails 2.2.2 gems should do the trick.

Ian.

So, where did you install MySQL and what version of it did you
install?

-Conrad

On 2 Mar 2009, at 2:37pm, Robert W. wrote:

working
just before you upgraded to Rails 2.2.2, but was there anything else
that you upgraded in the process? What version of Rails were you
running
before you upgraded to Rails 2.2.2? Did you install a new mysql gem
for
instance do you you have it installed at all?

Yes, of course - I should have done that initially but I didn’t want
to clutter the posting. See below.

I suppose what gets me irritated about this is that I had no prior
knowledge that upgrading Rails was going to disable what is probably
the most commonly-used database setup for Rails. Presumably there was
a good reason to remove the bundled MySQL driver, but I don’t know
what it is. I haven’t changed anything else on my system (apart from
Mac OS X updates) since I installed the machine nearly two years ago.

Is there a page somewhere (I looked but couldn’t find one) that sets
out the potentially adverse implications of upgrading to a particular
version of Rails? Seems like it would be a help.

Anyway, back to the error:

I can create a new Rails project using rails -d mysql myproject with
no problem, but when I run rake db:create:all I see this error message:

========= message ========
!!! The bundled mysql.rb driver has been removed from Rails 2.2.
Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load – mysql
========= message ========

Then when I run sudo gem install mysql I see this:

========= message ========
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

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
========= message ========

I had issues with mysql, but it didn’t take much Googling to find a
fix.
So I know for certain that Rails 2.2.2 will work just fine with MySQL,
as long as you have everything setup correctly. Chances are that if
you’re having trouble then others have had it already and posted the
fix
on their blog.

Well, yes, but like I said, the explanation is not that clear. For
example, I don’t know how to check whether libmysqlclient is
installed. Or how to swap from 64-bit MySQL to 32-bit MySQL.

If you really do end up needing to downgrade, then I would assume
uninstalling the Rails 2.2.2 gems should do the trick.

[sudo] gem uninstall rails --version 2.2.2
[sudo] gem uninstall actionmailer --version 2.2.2
[sudo] gem uninstall actionpack --version 2.2.2

I may have to try that if I can’t fix the current broken state. As an
alternative, I suppose I could specify an earlier Rails version in my
environment.rb file.

Thanks,

Ian.

On 2 Mar 2009, at 3:21pm, Conrad T. wrote:

So, where did you install MySQL and what version of it did you
install?

-Conrad

/usr/local/mysql - that was the location that the installer chose. I
am currently running MySQL version 5.0.45 on an Intel iMac with Mac OS
X 10.5.6. And I haven’t changed anything recently apart from upgrading
from Rails 2.1.0 (where things worked fine) to Rails 2.2.2 (where they
don’t).

:slight_smile:

Ian.

On Mon, Mar 2, 2009 at 7:35 AM, Ian P. [email protected] wrote:

X 10.5.6. And I haven’t changed anything recently apart from upgrading
from Rails 2.1.0 (where things worked fine) to Rails 2.2.2 (where they
don’t).

:slight_smile:

OK, where is the following file located:

mysql_config

Once you located the parent directory of the above file, you should be
able
to
do the following:

sudo gem install kwatch-mysql-ruby –
–with-mysql-config=<insert_parent_directory_here>/mysql_config

Good luck,

-Conrad

Ian P. wrote:

Then when I run sudo gem install mysql I see this:

On Mac OS X you can’t just simply run sudo gem install mysql. You must
use the instructions that are specific to Mac OS X.

This really has to do with the nature of Mac OS X Leopard and is
somewhat unrelated to Rails or Ruby.

Mac OS X 10.5 (Leopard) builds universal binaries by default. However,
most installations of MySQL on Mac OS 10.5 are Intel only so you must
tell the gcc compiler to build for your specific platform: i386 or ppc.

Here is the command to use to install the mysql gem for Intel:

sudo env ARCHFLAGS="-arch i386" gem install mysql
–with-mysql-config=/usr/local/mysql/bin/mysql_config

Note: That is all one line.

However, you may still have an issue with one of the dynamic libraries.
This is where I had an issue with my install.

Here is the fix:

sudo install_name_tool -change
/usr/local/mysql/lib/mysql/libmysqlclient.15.dylib
/usr/local/mysql/libmysqlclient.15.dylib
/Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle

Note: You may need to confirm the paths in that command, because some of
the blogs I tried didn’t have it correct and I’m not sure if this one is
one of those. So make sure the libmysqlclient.15.dylib is actually in
the location specified above. Same goes for the mysql.bundle path.

On Mon, Mar 2, 2009 at 7:52 AM, Robert W. <
[email protected]> wrote:

Mac OS X 10.5 (Leopard) builds universal binaries by default. However,
However, you may still have an issue with one of the dynamic libraries.
the blogs I tried didn’t have it correct and I’m not sure if this one is
one of those. So make sure the libmysqlclient.15.dylib is actually in
the location specified above. Same goes for the mysql.bundle path.

Posted via http://www.ruby-forum.com/.

Hi, I have both Intel and G5 Macs and I was able to simply install MySQL
without
requiring any architecture flags.

-Conrad

Conrad T. wrote:

Hi, I have both Intel and G5 Macs and I was able to simply install MySQL
without
requiring any architecture flags.

I didn’t say it was required to install MySQL. It is, however, necessary
for installing the mysql gem using RubyGems on Mac OS X Leopard.

Note: It’s not required for Mac OS X 10.4 (Tiger).

On Mon, Mar 2, 2009 at 8:08 AM, Robert W. <
[email protected]> wrote:

Hi, I’m running Mac OS X Leopard and it’s not required on my systems.

-Conrad

On 2 Mar 2009, at 3:44pm, Conrad T. wrote:

am currently running MySQL version 5.0.45 on an Intel iMac with Mac OS
Once you located the parent directory of the above file, you should
be able to
do the following:

sudo gem install kwatch-mysql-ruby – --with-mysql-
config=<insert_parent_directory_here>/mysql_config

Thanks - unfortunately, this didn’t work… here is the transcript:

=====
frost:euops ian$ which mysql_config
/usr/local/mysql/bin/mysql_config
frost:euops ian$ sudo gem install kwatch-mysql-ruby – --with-mysql-
config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while…
Successfully installed kwatch-mysql-ruby-2.8.1
1 gem installed
frost:euops ian$ rake db:create:all
(in /Users/ian/projects/rails/euops)
!!! The bundled mysql.rb driver has been removed from Rails 2.2.
Please install the mysql gem and try again: gem install mysql.
rake aborted!
dlopen(/Library/Ruby/Gems/1.8/gems/kwatch-mysql-ruby-2.8.1/lib/
mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/mysql/
libmysqlclient.15.dylib
Referenced from: /Library/Ruby/Gems/1.8/gems/kwatch-mysql-
ruby-2.8.1/lib/mysql.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/kwatch-mysql-
ruby-2.8.1/lib/mysql.bundle

though the bundle is there:

=====
frost:euops ian$ ls -al /Library/Ruby/Gems/1.8/gems/kwatch-mysql-
ruby-2.8.1/lib/
total 352
drwxr-xr-x 3 root admin 102 2 Mar 15:50 .
drwxr-xr-x 12 root admin 408 2 Mar 15:50 …
-rwxr-xr-x 1 root admin 176560 2 Mar 15:50 mysql.bundle

Would it make sense to completely clear out my Rails installation and
start again?

BTW, regarding Robert’s posting about architecture flags, I have never
done this on my Intel Macs and never previously had a problem. So I
don’t think that’s the answer (though I could be wrong - wouldn’t be
the first time).

Ian.

Robert W. wrote:

Conrad T. wrote:

Hi, I have both Intel and G5 Macs and I was able to simply install MySQL
without
requiring any architecture flags.

I didn’t say it was required to install MySQL. It is, however, necessary
for installing the mysql gem using RubyGems on Mac OS X Leopard.

Note: It’s not required for Mac OS X 10.4 (Tiger).

By the way that command for installing the mysql gem I posted was
straight out of the instructions in comments at the top of the
database.yml file for a new Rails 2.2.2 project, which looks something
like:

MySQL. Versions 4.1 and 5.0 are recommended.

Install the MySQL driver:

gem install mysql

On Mac OS X:

sudo gem install mysql – --with-mysql-dir=/usr/local/mysql

On Mac OS X Leopard:

sudo env ARCHFLAGS="-arch i386" gem install mysql –

–with-mysql-config=/usr/local/mysql/bin/mysql_config

This sets the ARCHFLAGS environment variable to your native

architecture

Robert W. wrote:

On Mac OS X Leopard:

sudo env ARCHFLAGS="-arch i386" gem install mysql –

–with-mysql-config=/usr/local/mysql/bin/mysql_config

This sets the ARCHFLAGS environment variable to your native

architecture

I just realized that the command I posted earlier was missing the extra
– after mysql and before --with-my…

So make sure you use the command exactly as above and it should work
fine. If you happen to have a PowerPC based mac running leopard, be sure
to switch out -i386 with -ppc.

On Mon, Mar 2, 2009 at 8:22 AM, Robert W. <
[email protected]> wrote:

So make sure you use the command exactly as above and it should work
fine. If you happen to have a PowerPC based mac running leopard, be sure
to switch out -i386 with -ppc.

I guess it really depends on your environment because I have been
install
MySQL gems
for over a year with having to require the architecture. Every
environment
is different.

-Conrad

On Mon, Mar 2, 2009 at 8:31 AM, Conrad T. [email protected]
wrote:

I just realized that the command I posted earlier was missing the extra
– after mysql and before --with-my…

So make sure you use the command exactly as above and it should work
fine. If you happen to have a PowerPC based mac running leopard, be sure
to switch out -i386 with -ppc.

I guess it really depends on your environment because I have been
installing
MySQL gems
for over a year without having to require the architecture. Every
environment is different.

-Conrad

On 2 Mar 2009, at 4:22pm, Robert W. wrote:

– after mysql and before --with-my…

So make sure you use the command exactly as above and it should work
fine. If you happen to have a PowerPC based mac running leopard, be
sure
to switch out -i386 with -ppc.

OK, sorted. Thanks for all of your help. Here, for the record, is what
I did, based on your collected suggestions:

  1. I ran this command (all on one line):
    sudo env ARCHFLAGS="-arch i386" gem install mysql – --with-mysql-
    config=/usr/local/mysql/bin/mysql_config

  2. I did the install_name_tool thing (also all on one line - note the
    paths carefully - the first is the wrong path, the second is the
    correct path and the third should also be correct):
    sudo install_name_tool -change /usr/local/mysql/lib/mysql/
    libmysqlclient.15.dylib /usr/local/mysql/lib/libmysqlclient.15.dylib

  3. To test, I created a new mysql project, changed to the project
    folder, edited the username and password in config/database.yml and
    then typed rake db:create:all. This just returned the command prompt
    with no error.

Here is the transcript:

==== transcript ====

frost:rails ian$ sudo env ARCHFLAGS="-arch i386" gem install mysql –
–with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while…
Successfully installed mysql-2.7
1 gem installed

frost:rails ian$ sudo install_name_tool -change /usr/local/mysql/lib/
mysql/libmysqlclient.15.dylib /usr/local/mysql/lib/libmysqlclient.
15.dylib /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle

frost:rails ian$ rails -d mysql dbtest

frost:rails ian$ cd dbtest

frost:dbtest ian$ rake db:create:all

==== transcript ====

Ian.

Ian - if I’m not mistaken, kwatch-mysql-ruby provides mysql-2.8.1
which is the correct version for Ruby-1.9.+. You only said your
upgrade was to Rails 2.2 and your gems messages indicate /System/
Library/…/gems/1.8/gems so I’m guessing you are still running Ruby
1.8.[67].

Try the install that you used for kwatch but instead of “kwatch-mysql-
ruby” use “mysql-ruby” that ought to work for you.