views:

38073

answers:

20

I upgraded to Snow Leopard using the disc we got at WWDC.

Trying to run some of my rails apps now complains about sql

    (in /Users/coneybeare/Projects/Ambiance/ambiance-server)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
Importing all sounds in /Users/coneybeare/Projects/Ambiance/ambiance-sounds/Import 32/Compressed/

 -- AdirondackPeepers.caf
!!! 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(/opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/libmysqlclient.16.dylib
  Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
  Reason: image not found - /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle

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

I could have sworn I fixed this once before. The problem is that

sudo gem install mysql

does not work and gives the error:

 Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

/opt/local/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 /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

Has anybody gotten mysql to work with rails on snow leopard yet? If so, what is your setup and better yet, what can I do to reproduce it?

A: 

I am assuming since you are using /opt/ that your rails and mysql came from either fink or macports. If am correct as there you will probably find more people that have seen your problem. Sorry for not helping you out with your actual problem though

hhafez
+2  A: 

I have seen this problem many times. almost everytime I build mysql on a machine. I think, you have to pass your mysqlconfig as part of the gem install command.

sudo gem install mysql -- --with-mysql-config=/your/mysql/config

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=/usr/bin/ruby
--with-mysql-config

Remember that you need mysql dev files to be able to build this gem.

Ryan Oberoi
A: 

I thought I would answer my own question here. It seems as if the problem isnt in mysql, but in the mysql ruby bindings. I figured this out because when I hooked up Querius (my mysql gui), it was able to connect.

Here is how to build from source fix the bindings:

cd /tmp
wget http://www.tmtm.org/en/ruby/mysql/ruby-mysql-0.2.6.tar.gz
tar xvfz ruby-mysql-0.2.6.tar.gz
cd ruby-mysql-0.2.6
./configure
make
sudo make install

There are plenty of libraries that I will have to build from source on Snow Leopard and they keep popping up. MacPorts doesnt seem to be updated enough for all the libs so I'm off to do it on my own. Next up: freetype (http://download.savannah.gnu.org/releases-noredirect/freetype/)

coneybeare
yeah ruby-mysql isn't the best way to go. The mysql gem and other people have advocated it. It really is a better way to go. I'm not going to downvote as this appears to be adequate, but it's definately not the best way.
railsninja
A: 

I proceeded like explained in this post (http://www.schmidp.com/2009/06/14/rubyrails-and-mysql-on-snow-leopard-10a380/), and everything now works fine.

Remember to lookout for the typos in his command to install the mysql driver.

+3  A: 

I fought with this for a long time and finally got it working on Snow Leopard. I ended up installing Ruby, RubyGems, and MySQL from source (see the Hivelogic tutorial for installing Ruby and RubyGems. The MySQL tutorial is linked at the bottom). I finally got the gem to install, but I was still getting

dyld: lazy symbol binding failed: Symbol not found: _mysql_init
  Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_init
  Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
  Expected in: flat namespace

Trace/BPT trap

I finally deleted the mysql.bundle (I have no idea what this is for) and it all worked.

sudo rm -f /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle

Hope that helps someone.

Sam Soffes
Man, thanks for the heads up on the mysql.bundle. That burned me on one of my machines.
Scott
That helped me, thanks man!
Michiel de Mare
+3  A: 

Rebuilding mysql as 64bit or installing the 64bit version is important, but you also need to make sure you build the native parts of the mysql gem as 64bit as well (this doesn't apply if you are on one of the original Intel Core Duo macs).

Here's the magic command:

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

You should set the ARCHFLAGS as shown above whenever you do a gem install with native components on Snow Leopard.

Shebanator
I have one of the original Core Duo macs (1st gen Macbook), so no 64-bit CPU. How would you modify your command for this architecture?
Martijn Heemels
For 32-bit Macbook or Macbook Pro, install the regular x86 version of MySQL and use this command: sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Martijn Heemels
Yes, if you have the 1st gen macbooks, you should just leave out all this stuff before the gem command.
Shebanator
Also, the rubyonrails.org site now has detailed instructions on how to upgrade to snow leopard, which generally are better than the stuff on this page: http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopardIn particular, there is a nice script at the end for upgrading all your native gems.
Shebanator
+70  A: 

I just went through the same pain... here's what worked for me:

  1. Download / install the 64-bit MySQL 5.1.37 from mysql.com
  2. run the following commands:

    sudo gem update --system

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

I also uninstalled all mysql gems that were floating around from my 10.5 days, that may do it if the above doesn't work for you :)

Ian Selby
Thanks; you just save the rest of my hair!
Matt Darby
Thank you so much!
gdelfino
Good stuff. That was stumping me something awful.
littlerobothead
Perfect solution!
CalebHC
Works also on mysql updates/reinstalls! Thanks!
Leandro Ardissone
I wanted to expand on step #1 a little since installing mysql is half the battle.I downloaded this version of mysql as a zip not gzhttp://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.44.zipAnd I followed these instructions.http://hivelogic.com/articles/compiling-mysql-on-snow-leopardhttp://gist.github.com/178699I had no problems installing mysql with these steps then no problems running setp #2 from above.
jspooner
This worked for me. What was throwing me off what all of the links, including the rubyonrails.org wiki, that said NOT to install 64-bit mysql with Rails on OSX. Thanks!
Kyle Heironimus
Totally worked for me. Thanks!
Abel Martin
A: 

I had this same issue and here is what worked for me.

  1. Install Snow Leopard and the 64bit MySQL DMG.

  2. Create /etc/my.cnf to point to my previous MySQL data directory (as described here) and run

    sudo mysql_upgrade.

  3. Opened IRB and reinstall all of my gems using (via blog.costan.us/2009/07/rebuild-your-ruby-gems-if-you-update-to.html).

    \gem list\.each_line {|line| system 'sudo gem install #{line.split.first}'}

  4. Uninstalled the MySQL gems I had installed.

  5. Installed MySQL gem with

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

With that, everything seems to be working so far. *knock wood*

Aaron H.
This is on a MacBook Pro (pre-unibody) Core 2 Duo 2.4Ghz w/ 4Gb or RAM
Aaron H.
Did you boot up in 64 or 32-bit?
Jaryl
A: 

I'm having a combination of all the symptoms described by people in this thread. I'm not sure what hardware they're using, but I'm on one of the first C2D machines, which is a 32 bit kernel I believe (something about EFI?). This being said, should I be doing things differently (with i386 archtype, for instace?)

Mike
A: 

Thank you Ian Selby - followed your instructions and everything now works - I had been pulling my hair out for a few hours.

Gary Taylor
A: 

Mike is right ... if the EFI is 32.. no way to boot 64-bit kernel ! (no advice from Apple...) so none of all these posts floating around about X86-64 is right .... jumping into them brings a big big mess into the dev env...

A: 

Slightly unrelated, but in order to get do_sqlite3 correctly compiled on Snow Leopard you need to install it this way:

sudo env ARCHFLAGS="-arch x86_64" gem install do_sqlite3
Sean McCleary
+1  A: 

Hi,

I was having problems with getting my configuration to work after installing snow leopard. I found MAMP at http://www.mamp.info and it bundles Apache, PHP and MySQL. you install it like an application and it just works. Maybe worth giving it a try, and it is free.

mesh

A: 

I tried the archflags trick many times with slight variations but it never worked for me.

What finally did work was switching back to the version of ruby and gem installed with snow leopard.

I had built and installed my own version which has worked for me in every respect except this one. Since everything else seems to work fine, I can't help guessing the mysql plugin has some funky assumptions in it. Anyway, all I did was switch /usr/bin to be first in my path again. I had installed ruby in /usr/local/ruby-1.8.7 and /usr/local/ruby-1.9.1 to be able to easily switch. Thought I'd mention it since the archflags solution seems to work for many people, but not quite all.

Ian
A: 

I renamed the mysql_config program from $MYSQL_HOME/bin to something else so that the configuration script from the gem installer is unable to find it. Even though I was using the libs option, the gem installer did always use the compile settings from my mysql installation, which is fat binary. But the default ruby installation is only x86_64 and therefore the compile of the gem fails. After renaming the mysql_config program the following command worked just fine and installed the gem:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-dir=/usr/local/mysql
cmitt
A: 

this article solved the issue for me :)

http://techliberty.blogspot.com/2009/12/dealing-with-rake-aborted-uninitialized.html

Prior to Leopard: sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql

Leopard on a PPC machine: sudo env ARCHFLAGS="-arch ppc" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Leopard on an Intel machine: sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Snow Leopard (only on Intel): sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Bijan
A: 

If you are installing the mysql gem with RVM you need to use the following code to install it

sudo env ARCHFLAGS="-arch x86_64" gem install mysql

This method worked for me in Leopard Server, none of the above worked

ganar
A: 

This worked perfectly for me (I am using Snow Leopard on a Mac)

http://techliberty.blogspot.com/2009/12/dealing-with-rake-aborted-uninitialized.html

Asif Sheikh
A: 

Ian Selby answered this for me (Snow Leopard 64 bit mac book pro)

Steve
+1  A: 

If you're using bundler, you can use "bundle config" to set the proper build arguments for mysql like so:

bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
Steven Soroka
http://gembundler.com/
gdelfino
Yeah, this might have changed with bundler 1.0. It probably uses environment variables or something... I haven't had to explicitly set it with 1.0
Steven Soroka