68

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?

18 Answers 18

107

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

6
  • Thanks; you just save the rest of my hair!
    – Matt Darby
    Aug 28, 2009 at 23:06
  • Good stuff. That was stumping me something awful.
    – nickmjones
    Oct 14, 2009 at 3:45
  • 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 gz downloads.mysql.com/archives/mysql-5.1/mysql-5.1.44.zip And I followed these instructions. hivelogic.com/articles/compiling-mysql-on-snow-leopard gist.github.com/178699 I had no problems installing mysql with these steps then no problems running setp #2 from above.
    – jspooner
    Apr 8, 2010 at 17:02
  • 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! Jul 14, 2010 at 21:21
  • sorry don't want to sound dumb but is your method used instead of the sudo gem install mysql? is there any way to find out if the gem installed correctly? thanks I'm very new to mac and MYSQL and relatively new to ruby on rails.
    – Mo.
    Nov 30, 2010 at 22:57
10

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.

4
  • 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? Sep 18, 2009 at 14:43
  • 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 Sep 18, 2009 at 14:48
  • Yes, if you have the 1st gen macbooks, you should just leave out all this stuff before the gem command.
    – Shebanator
    Sep 18, 2009 at 15:39
  • 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: weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard In particular, there is a nice script at the end for upgrading all your native gems.
    – Shebanator
    Sep 18, 2009 at 15:55
7

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
1
  • 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 Sep 16, 2010 at 21:37
6

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.

2
  • 1
    Man, thanks for the heads up on the mysql.bundle. That burned me on one of my machines.
    – Scott
    Aug 29, 2009 at 22:49
  • 1
    "I finally deleted the mysql.bundle (I have no idea what this is for) and it all worked." By the same logic you might try to delete that big "mach_kernel" file or those "tmp" directories. Deleting things from the system that were installed by Apple is not a good idea. Research to understand why it is there first, then decide if it's OK to delete. Jan 2, 2012 at 8:30
4

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.

2

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

1

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

0
1

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.

1

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*

2
  • This is on a MacBook Pro (pre-unibody) Core 2 Duo 2.4Ghz w/ 4Gb or RAM
    – Aaron H.
    Aug 29, 2009 at 2:49
  • Did you boot up in 64 or 32-bit?
    – Jaryl
    Oct 15, 2010 at 11:20
1

In case you prefer homebrew, instead of installing MySQL manually.

Un-install the existing mysql gem (if any):

 sudo gem uninstall mysql 

Locate the ‘mysql_config’ file:

 find /usr -name 'mysql_config' 

Re-install mysql gem:

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

Note: replace /usr/local/bin/ with the corresponding mysql_config path found in step 2. Also on my blog.

1

Ian Selby thank you alot but I had to remove the sudo from in front of sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

I was installing to a gemset and am using rvm which I think asks you not to use the sudo keyword. Thanks alot.

1

I've solved it this way:

  1. after install dmg file of mysql  
  2. bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin//mysql_config
  3. env ARCHFLAGS="-arch x86_64"
  4. bundle install
1

Having had a break from Rails for several years, I just spent some time setting up my development environment. So thought I would create a tutorial on how to install the latest version of Rails 3, MySQL, and RVM on SnowLeopard, to hopefully save others some time who are in my position.

It works as of 21st August 2011, using Rails 3.0.10, MySQL 5.5.15, and RVM 1.7.2. It should work with future Rails 3.0.x, MySQL 5.5.x, and RVM 1.7.x versions.

  1. Install XCode if not already installed. I used 4.0.2. Unfortunately this has now been withdrawn by Apple, but may be available elsewhere on the Internet. Version 3.2.x is free to download from Apple, but I did not test it with this tutorial, it probably works too.

  2. Install rvm:

    user$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
    
    user$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
    
    user$ source .bash_profile
    
  3. Install a version of Ruby (e.g. 1.9.2) in rvm, basic usage instructions are here.

    user$ rvm install 1.9.2
    user$ rvm use 1.9.2
    
  4. Create a gemset for the rvm ruby installed in step 2 (x is the version number).

    user$ rvm gemset create rails30x
    user$ rvm 1.9.2@rails30x
    
  5. Install Rails 3.0.x (x is the version number).

    user$  gem install rails -v 3.0.x.
    
  6. Download and install the MySQL 5.5.x package, the startup item, and the preferences pane. All 3 of these are included in the DMG install file. Also install MySQL WorkBench.

    Find /usr/local/mysql-version-name/support-files (inserting the correct MySQL directory name) and edit mysql.server (with root privileges). Around line 46 locate the lines that read:

    basedir=
    datadir=
    

    and change them to read (inserting the correct MySQL directory name):

    basedir=/usr/local/mysql-version-name
    datadir=/usr/local/mysql-version-name/data
    

    Save the file. MySQL can now be started from the preferences pane.

    To enable rails 3 to use mysql, install the mysql2 gem (see next step). First, you’ll need to set the DYLD_LIBRARY_PATH to include the MySQL library directory. To do this, edit your ~/.bash_profile in your home folder and include the following (inserting the correct MySQL directory name):

    export DYLD_LIBRARY_PATH=/usr/local/mysql-version-name/lib:$DYLD_LIBRARY_PATH
    

    Without the inclusion of the directory in the DYLD_LIBRARY_PATH, a message about not finding the library would appear and the server would abort.

  7. Install the mysql2 gem. (as of May 2011, version 0.2.7 is the most recent working version with Rails 3.0.x).

    user$ gem install mysql2 -v 0.2.7 
    
  8. Create a rails app, and it's corresponding database (appname_development).

    user$ rails new appname
    
  9. Add this to the app's Gemfile: gem 'mysql2', "0.2.7"

  10. Add this to the app's database.yml:

    development: 
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: appname_development
      pool: 5
      username: username
      password: pwd
      host: localhost
    
  11. start app and check "About your application's environment". Everything should be working correctly.

2
1

The instructions for setting ARCHFLAGS and passing --mysql-config=... didn't seem to be quite enough to solve this for me on Snow Leopard. In addition to doing that, I added:

DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

to my bash profile, and this solved it for me.

0

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.

0

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
0

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.