views:

6349

answers:

9

I tried for about 3-4 hours trying to get the mysql gem to install for ruby 1.9.1 on snow leopard. The mysql gem used to work just fine on 1.9.1 before I upgraded to snow leopard. I uninstalled MySQL server and gem from my machine. I then downloaded and installed: mysql-5.1.37-osx10.5-x86_64.dmg. I have been able to assert that this new version I installed is running as a 64bit application.

I uninstalled the mysql gem. When I tried to install the gem with this command:

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

I got this error:

GET 304 Not Modified: http://gems.rubyforge.org/latest_specs.4.8.gz
GET 200 OK: http://gems.github.com/latest_specs.4.8.gz
Installing gem mysql-2.8.1
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/COPYING
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/COPYING.ja
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/History.txt
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/Manifest.txt
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/README.txt
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/Rakefile
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/ext/mysql_api/extconf.rb
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/ext/mysql_api/mysql.c
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/extra/README.html
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/extra/README_ja.html
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/extra/tommy.css
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/lib/mysql.rb
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/tasks/gem.rake
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/tasks/native.rake
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/tasks/vendor_mysql.rake
/Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/test/test_mysql.rb
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
        ERROR: Failed to build gem native extension.

/Users/sean/.rvm/ruby-1.9.1-p243/bin/ruby extconf.rb --with-mysql-config=/usr/local/mysql/bin/mysql_config
checking for mysql_ssl_set()... yes
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... yes
creating Makefile

make
gcc -I. -I/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/i386-darwin9.8.0 -I/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/backward -I/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1 -I. -DHAVE_MYSQL_SSL_SET -DHAVE_MYSQL_H  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE   -I/usr/local/mysql/include  -g -Os -arch x86_64 -fno-common   -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT  -DDONT_DECLARE_CXA_PURE_VIRTUAL -fno-common  -O2 -g -Wall -Wno-parentheses  -fno-common -pipe -fno-common  -o mysql.o -c mysql.c
In file included from /Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby.h:32,
                 from mysql.c:5:
/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/ruby.h: In function 'INT2NUM':
/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/ruby.h:464: warning: comparison is always true due to limited range of data type
/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/ruby.h:464: warning: comparison is always true due to limited range of data type
/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/ruby.h: In function 'UINT2NUM':
/Users/sean/.rvm/ruby-1.9.1-p243/include/ruby-1.9.1/ruby/ruby.h:472: warning: comparison is always true due to limited range of data type
mysql.c: In function 'escape_string':
mysql.c:290: error: lvalue required as left operand of assignment
mysql.c:290: error: lvalue required as left operand of assignment
mysql.c: In function 'real_escape_string':
mysql.c:434: error: lvalue required as left operand of assignment
mysql.c:434: error: lvalue required as left operand of assignment
make: *** [mysql.o] Error 1


Gem files will remain installed in /Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1 for inspection.
Results logged to /Users/sean/.gem/ruby/1.9.1/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

I have tried everything I have read from the following links.

  1. http://void-design.net/2009/08/05/ruby-191-mysql-and-a-snow-leopard/
  2. http://www.schmidp.com/2009/06/14/rubyrails-and-mysql-on-snow-leopard-10a380/
  3. http://stackoverflow.com/questions/991708/rails-mysql-and-snow-leopard

Any ideas?

+6  A: 

I solved this problem by installing MySQL from MacPorts and then running the same gem install command that you have up there.

So, first, uninstall the MySQL you have from the package:

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*

If you haven't done it yet, install MacPorts from here: http://www.macports.org/install.php There's a package for Snow Leopard.

Install mysql5-devel from MacPorts:

sudo port install mysql5-server-devel

It'll do all the dependencies and then MySQL. Follow all the post-install steps that the installer recommends - start-up items, etc. The MySQL it installs is 64-bit.

Then install the MySQL gem with:

env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/opt/local/bin/mysql_config5

Note the path changes there. MacPorts puts MySQL in different places.

You should be good to go.

Georges
I just gave your solution a try and I got the same error as before. I am not sure if I am going to need to try to recompile ruby 1.9.1.
Sean McCleary
Yeah, I hoped this would work for you, but I think your issue is Ruby 1.9.1. Using the default Snow Leopard ruby, it works. SL ruby is 1.8.7.
Georges
Did a little more investigation and found this: http://github.com/kwatch/mysql-ruby/tree/master
Georges
A: 

This worked great for me. I am on 10.6 snow, 1.87 ruby. Thanks

Salj
Salj, this is more suited to a comment rather than an answer.
The Wicked Flea
+1  A: 

I tried all the above steps with no luck, but discovered a workaround (or whatever) using the mysqlplus gem instead of the mysql gem:

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

And now my MySQL ruby apps work like a charm in Snow Leopard.

NateD
I'll have to give that a try. Thank you.
Sean McCleary
+1  A: 

Installing XCode was the solution for me

A: 

Take a look at this post: http://jameseggers.com/post/185690322/fix-mysql-and-rails-on-snow-leopard . It shows how to get MySQL + Ruby on Rails + Snow Leopard all working perfectly.

James Eggers
+10  A: 

Sean, I see that you are running Ruby 1.9.1 under rvm. I'm having the same problem under the same setup (Snow Leopard, rvm, MySQL 64-bit package). All of the alternate gems (mysqlplus, kwatch-mysql-ruby, etc) fail with the same error.

I would suspect the MySQL install, but everything works like a champ under the system default Ruby. So I wonder if rvm isn't the monkey wrench somehow.

EDIT: I figured it out. I installed rvm before upgrading to Snow Leopard, so my Ruby 1.9.1 install needed to be recompiled. For good measure, I reinstalled rvm from scratch.

Here's what I did:

sudo gem uninstall rvm
rm -rf ~/.gem
sudo gem install rvm
rvm-install
rvm install 1.9.1
rvm 1.9.1
env ARCHFLAGS="-arch x86_64" gem install mysql

(NOTE: You cannot use sudo when installing gems under rvm, because rvm works by modifying $PATH.)

(NOTE: I added /usr/local/mysql/bin to my $PATH so I didn't have to specify any of those awful command-line args when installing the mysql gem.)

The mysql gem installed without a hitch.

Jonathan Vaught
gravelpup, Thank you. That was perfect. I love RVM and your solution nailed it.
Sean McCleary
Awesome, glad to hear it. Now if I could just get my ImageMagick port to compile... Guess I'll go start another thread on that topic.
Jonathan Vaught
I've been having the same problem getting the mysql gem installed with ruby 1.9.1 under rvm having upgraded to Snow Leopard. I tried Jonathan's suggestion but to no avail. A bit more digging and it seems you need to `rm -rf ~/.rvm` instead of `rm -rf ~/.gem` as that's where rvm stores the vm specific gems.
fractious
N.B. This also solved a problem under ruby 1.9.2 where attempting to reinstall the mysql gem resulted in an error about the developer tools not being installed even though they *are*.
fractious
`rvm list` will show you the installed Rubies, along with the architecture they were compiled under. For Snow Leopard, you should have "x86_64", and if you had installed on a previous version of the OS odds are good it won't be. I ran into this a couple weeks ago and asked if there was a way to have RVM do the recompile in-place. The answer was you have to uninstall the Ruby in question (`rvm uninstall 1.9.1` and then install it again. You can then reload the gems as they should be intact. Some might be compiled for the wrong architecture too so you'll have to `gem uninstall ...` those too.
Greg
I'd recommend moving from 1.9.1 to 1.9.2. 1.9.2 is better behaved. I was seeing compile problems with 1.9.1 that went away after upgrading, and now I don't even bother installing it. I just have 1.8.7.something for backwards compatibility, and 1.9.2.p0
Greg
A: 

Found a great tutorial online for this.

http://www.icoretech.org/2009/08/install-mysql-and-mysql-ruby-gem-on-snow-leopard-64-bit/

Setting the PATH variable was my problem.

Ryan Michela
A: 

I had the same problem with mysql gem, rvm and ruby 1.9.1. As mentioned in my post at NeptunePhoenix, I had success by installing mysql via port.

NeptunePhoenix
A: 

Struggled for hours before stumbling on this:

http://markgandolfo.com/2010/08/21/mysql-gem-with-rails-3-and-ruby-1-9-2

Scott