Rails, MySQL and Snow Leopard

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

Trying to run some of my rail applications 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 swear I fixed it before. The problem is that

 sudo gem install mysql 

does not work and gives an 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 anyone got mysql to work with rails on a snow leopard? If so, what is your setup and even better, what can I do to reproduce it?

+67
ruby mysql ruby-on-rails osx-snow-leopard
Jun 13 '09 at 22:53
source share
18 answers

I just experienced the same pain ... this is what worked for me:

  • Download / install 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 removed all mysql stones that floated around my 10.5 days, which can do this if the above does not work for you :)

+108
Aug 28 '09 at 21:51
source share

Rebuilding mysql as a 64-bit or installing a 64-bit version is important, but you also need to make sure that you create your own mysql gem parts as 64-bit (this does not apply if you are on one of the original Intel Core Duo processors macs).

Here's the magic command:

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

You must install ARCHFLAGS as shown above whenever you install gem using native components on Snow Leopard.

+10
Aug 28 '09 at 5:25
source share

If you are using bundler, you can use "config bundle" to set the correct build arguments for mysql as follows:

 bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config 
+7
Aug 23 '10 at 18:30
source share

I struggled with this for a long time and finally worked on Snow Leopard. I finished installing Ruby, RubyGems, and MySQL from the source (see the Hivelogic tutorial for installing Ruby and RubyGems. The MySQL tutorial is linked below). I finally got a stone to set, but I still got

 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 

Finally, I deleted 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 this helps someone.

+6
Aug 6 '09 at 21:10
source share

I have seen this problem many times. almost every time i build mysql on a machine. I think you need 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 create this gem.

+4
Jun 13 '09 at 23:59
source share

I am having trouble adjusting my configuration after installing a snow leopard. I found MAMP at http://www.mamp.info and it links Apache, PHP and MySQL. you install it as an application and it just works. It may be worth a try, and it's free.

grid

+2
Sep 14 '09 at 10:50
source share

I thought I would answer my question. It seems that the problem is not in mysql, but in bindings ruby ​​mysql. I realized this because when I connected Querius (my mysql gui), it was able to connect.

Here's how to build bindings from the original fixes:

 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 many libraries that I will have to build from a source on Snow Leopard, and they continue to appear. MacPorts doesn't seem to be updated enough for all libraries, so I can do it myself. Next: freetype ( http://download.savannah.gnu.org/releases-noredirect/freetype/ )

+1
Jun 14 '09 at 4:19
source share

I continued as described in this post ( http://www.schmidp.com/2009/06/14/rubyrails-and-mysql-on-snow-leopard-10a380/ ) and now everything is working fine.

Remember to keep track of typos in his command to install the mysql driver.

+1
Jul 15 '09 at 12:39
source share

I had the same problem and this is what worked for me.

  • Install Snow Leopard and 64-bit MySQL DMG.

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

    sudo mysql_upgrade .

  • Open IRB and reinstall all 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}'}

  • The MySQL utility that I installed.

  • Installed MySQL using

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

With this, everything seems to be working so far. * knock out a tree *

+1
Aug 28 '09 at 22:38
source share

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

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

into my bash profile and this solved it for me.

+1
Dec 27 '10 at 18:45
source share

If you prefer home brew , instead of installing MySQL manually.

Disable the existing mysql verb (if any):

  sudo gem uninstall mysql 

Locate the mysql_config file:

  find /usr -name 'mysql_config' 

Reinstall 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 appropriate mysql_config path found in step 2. Also on my blog .

+1
Jan 17 2018-11-11T00:
source share

Ian Selby, thank you very much, but I had to remove sudo before sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

I installed in gemset and use rvm, which I think asks you not to use the sudo keyword. Thank you very much.

+1
Feb 04 2018-11-11T00:
source share

I solved it like this:

  • after installing dmg mysql file
  • bundle config build.mysql --with-mysql-config = / usr / local / mysql / bin // mysql_config
  • env ARCHFLAGS = "- arch x86_64"
  • install package
+1
Apr 04 2018-11-11T00:
source share

After several breaks with Rails, I spent some time creating a development environment. So I thought I was going to create a tutorial on how to install the latest version of Rails 3, MySQL and RVM on SnowLeopard in order to hope to keep other people in my place.

It has been working since August 21, 2011 using Rails 3.0.10, MySQL 5.5.15 and RVM 1.7.2. It should work with future versions of Rails version 3.0.x, MySQL 5.5.x and RVM 1.7.x.

  • Install Xcode if it is not already installed. I used 4.0.2. Unfortunately, this has now been shot by Apple, but may be available elsewhere on the Internet. Version 3.2.x can be downloaded for free from Apple, but I have not tested it with this guide, maybe this also works.

  • 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 
  • Install the Ruby version (e.g. 1.9.2) in rvm, the basic usage instructions are here .

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

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

     user$ gem install rails -v 3.0.x. 
  • Download and install the MySQL 5.5.x package, startup item, and settings panel . All three of them are included in the DMG installation file. Also install MySQL WorkBench.

    Locate / usr / local / mysql-version-name / support-files (insert the correct MySQL directory name) and edit mysql.server (with root privileges). Around line 46, find the lines that are being read:

     basedir= datadir= 

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

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

    Save the file. Now MySQL can be started from the settings panel.

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

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

    Without including the directory in DYLD_LIBRARY_PATH the message about the absence of the library and the server will be interrupted.

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

     user$ gem install mysql2 -v 0.2.7 
  • Create a rails application and its corresponding database (appname_development).

     user$ rails new appname 
  • Add this to your Gemfile application: gem 'mysql2', "0.2.7"

  • Add this to database.yml application:

     development: adapter: mysql2 encoding: utf8 reconnect: false database: appname_development pool: 5 username: username password: pwd host: localhost 
  • run the application and check "About your application environment". Everything should work correctly.

+1
Aug 21 '11 at 15:09
source share

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

As a result, finally, the work switched to the version of ruby ​​and precious stones, installed with the help of a snow leopard.

I created and installed my own version, which worked for me in every way except this. Since everything else is working fine, I cannot guess that there are some funky assumptions in the mysql plugin. Anyway, all I did was switch / usr / bin, to be the first in my path again. I was able to set the ruby ​​to / usr / local / ruby ​​-1.8.7 and / usr / local / ruby-1.9.1 to be able to switch easily. I think I would mention this, since the archflags solution seems to work for many people, but not quite for everyone.

0
Nov 02 '09 at 8:00
source share

I renamed the mysql_config program from $ MYSQL_HOME / bin to another so that I could not find the script configuration from the gem installer. Although I used the libs option, the gem installer always used the compilation options from my mysql installation, which is a bold binary. But the default ruby ​​setting is only x86_64, and therefore the compilation of the pearl fails. After renaming the mysql_config program, the following command did a great job and installed the gem:

 sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-dir=/usr/local/mysql 
0
Mar 04 '10 at 13:01
source share

this article solved the problem for me :)

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

  • 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 (Intel only):

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

0
Mar 05 '10 at 9:41
source share

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 on Leopard Server, none of the above

0
May 19 '10 at 23:43
source share



All Articles