MYSQL Installation Troubles

installationmacosmysqlruby-on-rails

After upgrading a few gems via terminal on my mac, I have created a new rails project backed up by a mysql database. Upon starting the app, the regular welcome aboard page appears.

Here's the problem – I tried clicking the link entitled "About your application's environment", I receive the following output in my browser:

MissingSourceFile in Rails/infoController#properties
no such file to load -- mysql

I also receive this output in the terminal

The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
Processing Rails::InfoController#properties (for 127.0.0.1 at 2008-12-09 20:41:41) [GET]
Processing Rails::InfoController#properties (for 127.0.0.1 at 2008-12-09 20:41:41) [GET]
MissingSourceFile (no such file to load -- mysql):
...

As it says, I tried issuing "gem install mysql" after stopping the application, only to be greeted by this chunk of jargon which I am unable to comprehend:

WARNING:  Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
      /usr/bin aren't both writable.
WARNING:  You don't have /Users/mymac/.gem/ruby/1.8/bin in your PATH,
      gem executables will not run.
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 /Users/mymac/.gem/ruby/1.8/gems/mysql-2.7 for inspection.
Results logged to /Users/mymac/.gem/ruby/1.8/gems/mysql-2.7/gem_make.out

Clearly there is something wrong with my mysql installation, as I have also tried running the rake command to create the database, which prompted me with the following.

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

(See full trace by running task with --trace)

However, when I run "mysql –version" at the command line, mysql is installed!

mysql  Ver 14.12 Distrib 5.0.67, for apple-darwin9.4.0 (i686) using readline 5.1

I also tried issuing "sudo gem install mysql", however that was also to no avail:

sudo 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


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 also tried issuing "sudo gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config" as instructed by bradheintz, which seemed to have installed ok, but after trying to view the application environment again, no ajaxy dropdown occurs and the rails app stops completely! The following output is printed just before the application decides to die on me lol.

dyld: lazy symbol binding failed: Symbol not found: _mysql_init
  Referenced from: /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle
  Expected in: dynamic lookup

dyld: Symbol not found: _mysql_init
  Referenced from: /Library/Ruby/Gems/1.8/gems/mysql-2.7/lib/mysql.bundle
  Expected in: dynamic lookup

Trace/BPT trap

If anyone can understand what's going on here, and how to go about resolving this problem, I'd be very grateful 🙂

Best Solution

The issue is that the MySQL gem builds native extensions and needs system-specific information about where to find certain libraries. You have to provide this on the command line.

Check out this page - the important bit (that worked for me, anyway) was:

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

Of course, be sure to substitute the correct path for your own system.

Also, stick with running your gem install commands via sudo.

The bigger issue is that the gem software provides NO feedback regarding the fact that you can't just do gem install mysql like you do with every other gem (and indeed, used to be able to do with the MySQL gem).