Rails, MySQL and Snow Leopard
Solution 1
I just went through the same pain... here's what worked for me:
- Download / install the 64-bit MySQL 5.1.37 from mysql.com
- 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 :)
Solution 2
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.
Solution 3
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
Solution 4
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.
Solution 5
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.
coneybeare
http://matt.coneybeare.me @coneybeare I have had a ton iOS apps under my name and my business name. I have multiple client apps, and one from an established startup. Many of my apps have been featured by Apple. I developed two iOS apps that made it into the top 100. One of the apps held the number two spot for three weeks. Another floats in/out of the paid News top 10. My apps have over 10 million downloads. I do a ton of web work too using rails for all my sites. I do much of my own design for all the sites I have created.
Updated on June 28, 2020Comments
-
coneybeare almost 4 years
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?
-
Matt Darby over 14 yearsThanks; you just save the rest of my hair!
-
Scott over 14 yearsMan, thanks for the heads up on the mysql.bundle. That burned me on one of my machines.
-
Devplex over 14 yearsI 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?
-
Devplex over 14 yearsFor 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
-
Shebanator over 14 yearsYes, if you have the 1st gen macbooks, you should just leave out all this stuff before the gem command.
-
Shebanator over 14 yearsAlso, 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.
-
nickmjones over 14 yearsGood stuff. That was stumping me something awful.
-
blakkheartt12 about 14 yearsI 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.
-
Kyle Heironimus almost 14 yearsThis 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!
-
Steven Soroka over 13 yearsYeah, 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
-
Mo. over 13 yearssorry 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.
-
Xiong Chiamiov about 13 years@Mo: This method uses
gem install mysql
- look closely. -
Paŭlo Ebermann over 12 yearsWelcome to Stack Overflow. Nice guide here. (I updated the formatting a bit.)
-
PJP over 12 years"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.
-
New Alexandria about 12 yearsIn some instances, RVM creates this problem