Rails 2.2.2, Mac OS X and MySQL

6 views
Skip to first unread message

Ian Piper

unread,
Mar 2, 2009, 9:12:32 AM3/2/09
to rubyonra...@googlegroups.com
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.
--

Robert Walker

unread,
Mar 2, 2009, 9:37:53 AM3/2/09
to rubyonra...@googlegroups.com
Ian Piper 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
...
--
Posted via http://www.ruby-forum.com/.

Conrad Taylor

unread,
Mar 2, 2009, 9:48:01 AM3/2/09
to rubyonra...@googlegroups.com
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

Ian Piper

unread,
Mar 2, 2009, 10:12:38 AM3/2/09
to rubyonra...@googlegroups.com
On 2 Mar 2009, at 2:37pm, Robert Walker wrote:

>
> Ian Piper 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?


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

Conrad Taylor

unread,
Mar 2, 2009, 10:21:42 AM3/2/09
to rubyonra...@googlegroups.com
So, where did you install MySQL and what version of it did you
install?

-Conrad


Ian Piper

unread,
Mar 2, 2009, 10:35:24 AM3/2/09
to rubyonra...@googlegroups.com
On 2 Mar 2009, at 3:21pm, Conrad Taylor 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).

:-)


Ian.
--

Conrad Taylor

unread,
Mar 2, 2009, 10:44:01 AM3/2/09
to rubyonra...@googlegroups.com
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

Robert Walker

unread,
Mar 2, 2009, 10:52:30 AM3/2/09
to rubyonra...@googlegroups.com
Ian Piper 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.

Conrad Taylor

unread,
Mar 2, 2009, 10:59:07 AM3/2/09
to rubyonra...@googlegroups.com
Hi, I have both Intel and G5 Macs and I was able to simply install MySQL without
requiring any architecture flags.

-Conrad
 



Ian Piper

unread,
Mar 2, 2009, 11:05:00 AM3/2/09
to rubyonra...@googlegroups.com
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 Walker

unread,
Mar 2, 2009, 11:08:52 AM3/2/09
to rubyonra...@googlegroups.com
Conrad Taylor 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).

Conrad Taylor

unread,
Mar 2, 2009, 11:11:08 AM3/2/09
to rubyonra...@googlegroups.com
On Mon, Mar 2, 2009 at 8:08 AM, Robert Walker <rails-mai...@andreas-s.net> wrote:

Conrad Taylor 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).

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

-Conrad

Robert Walker

unread,
Mar 2, 2009, 11:16:13 AM3/2/09
to rubyonra...@googlegroups.com
Robert Walker wrote:
> Conrad Taylor 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 Walker

unread,
Mar 2, 2009, 11:22:58 AM3/2/09
to rubyonra...@googlegroups.com
Robert Walker 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.

Conrad Taylor

unread,
Mar 2, 2009, 11:31:56 AM3/2/09
to rubyonra...@googlegroups.com
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

Conrad Taylor

unread,
Mar 2, 2009, 11:32:59 AM3/2/09
to rubyonra...@googlegroups.com
On Mon, Mar 2, 2009 at 8:31 AM, Conrad Taylor <conr...@gmail.com> wrote:
On Mon, Mar 2, 2009 at 8:22 AM, Robert Walker <rails-mai...@andreas-s.net> wrote:

Robert Walker 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.
 
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



Ian Piper

unread,
Mar 2, 2009, 12:28:01 PM3/2/09
to rubyonra...@googlegroups.com


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

Rick

unread,
Mar 2, 2009, 12:35:00 PM3/2/09
to Ruby on Rails: Talk
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.
Reply all
Reply to author
Forward
0 new messages