6

I am using MAMP2, rvm on OS X Lion and there is no way I can get mysql2 gem to work with my Rails app.

I've followed this blog post http://blog.mirotin.net/35/mamp-1-9-5-mysql-5-5-9-and-ruby-mysql2 and this one http://www.pa-ket.com/blog/show/12-osx-ruby-mysql2-gem-python-mysqldb-using-mamp

These were the steps:

$ cd /tmp
$ mv /Users/yourname/Desktop/mysql-5.5.9.tar.gz .
$ tar xf mysql-5.5.9.tar.gz
$ cd mysql-5.5.9
$ brew install cmake
$ cmake . -DMYSQL_UNIX_ADDR=/Applications/MAMP/tmp/mysql/mysql.sock -DCMAKE_INSTALL_PREFIX=/Applications/MAMP/Library

This step failed:

$ make -j 3

After commenting unit tests for 'my_atomic-t.dir' in /tmp/mysql-5.5.9/CMakeFiles/Makefile2 'make -j 3' went ok.

$ cp libmysql/*.dylib /Applications/MAMP/Library/lib/
$ mkdir -p /Applications/MAMP/Library/include/mysql
$ cp include/* /Applications/MAMP/Library/include/mysql
$ env ARCHFLAGS="-arch x86_64" gem install mysql2 -v 0.2.11 -- --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config
Building native extensions.  This could take a while...
Successfully installed mysql2-0.2.11
1 gem installed
Installing ri documentation for mysql2-0.2.11...
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.11...
Enclosing class/module 'mMysql2' for class Client not known

I guess 'Client not known' warning was nothing critical.
And the final step:

install_name_tool -change /tmp/mysql-5.5.9/libmysql/libmysqlclient.16.dylib /Applications/MAMP/Library/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.2-p290@global/gems/mysql2-0.2.11/ext/mysql2/mysql2.bundle

And the error I get when starting rails server:

$ rails server
=> Booting WEBrick
=> Rails 3.0.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[FATAL] failed to allocate memory

I just can't set that mysql2 gem and I've been trying for weeks. After numerous errors trying to install mysql2 gem, this is where I'm completely stuck.

I am using RVM and ruby-1.9.2-p290 on OS X Lion with MAMP 2.0.3 and Rails 3.0.7.

Any help is greatly appreciated!

Mirko
  • 5,207
  • 2
  • 37
  • 33
  • 1
    Similar error: http://stackoverflow.com/questions/7056157/mac-osx-lion-and-ruby-fatal-failed-to-allocate-memory – Mirko Sep 20 '11 at 19:53
  • I just repeated all steps including 'make -j 3' on a SnowLeopard machine and everything works with no problems. So this must be a Lion issue. – Mirko Sep 20 '11 at 22:08
  • Mirko, did you get this fixed? – jBeas Sep 28 '11 at 14:56
  • I posted an answer to a similar question [here](http://stackoverflow.com/questions/7332346/fatal-failed-to-allocate-memory-rails-3-1-and-mysql2-gem/7628474#7628474). It *may* be of some help. – providence Oct 02 '11 at 18:52
  • Mirko, have you solved this yet? I'm having similar issues... – easyjo Nov 08 '11 at 11:30
  • No, I haven't. I ended up setting Apache and PHP following this link http://echodittolabs.org/blog/2011/08/os-x-107-lion-development-native-mamp-mysql-installer and installing MySQL with Homebrew, completely wiping out MAMP. – Mirko Nov 08 '11 at 21:16

3 Answers3

13

I resolved this problem uninstalling mysql-connector-c and recompiling mysql2 gem with include and lib flags from brewed mysql server.

$ brew uninstall mysql-connector-c
$ gem uninstall mysql2
$ gem install mysql2 -- --with-mysql-include=/usr/local/Cellar/mysql/5.5.19/include --with-mysql-lib=/usr/local/Cellar/mysql/5.5.19/lib

http://abisso.org/2012/03/failed-to-allocate-memory/

nolith
  • 613
  • 6
  • 16
4

You should not use MAMP for this.

I read what you are trying to do. Your problem is not the mysql2 gem. Your problem is your installation of mysql.

Follow this article showing using homebrew to install mysql. It is very simple and takes about 10-15 minutes including install time to get it setup.

http://blog.theablefew.com/very-simple-homebrew-mysql-and-rails

Side note with using brew to install mysql. After you install mysql and it succeeds it will spit out a ton of information, and you need to look at it carefully because there are 1-2 lines among all the other junk that are instructions, pasting some stuff, etc...

My Setup:

Currently in my setup i have MAMP (for my /sites directory) when doing simple stuff like wordpress sites, etc... Then i have my homebrew install of mysql for rails (eventually i switched to sqlite/pg for heroku). Yes, i can run them at the same time. I have this setup because my projects require me to jump around between rails apps, static html landing pages, and a few older php projects, and I like the separation having 2 mysql installs.

jBeas
  • 926
  • 7
  • 20
  • Thank you for your answer. I've managed on both Leopard and Snow Leopard to have only MAMP's mysql, and I would really like to have it the same for Lion. I'm currently using ruby-mysql gem, but I will try to downgrade MAMP to 1.x when I get some time, as it seems by those blog posts that will work. My last resort will be another mysql instance with homebrew... – Mirko Sep 29 '11 at 00:39
  • I would, i looked at that link in your post and you were having trouble with this for the past month. Where is the fun in that? Time to write some awesome code!! I hate server admin stuff, not my bag. I also don't have any performance issues at all if you were worried about that. Also, after a while i just switched to sqlite, i see no reason to stick with mysql, especially if it's already causing so much trouble on your system. – jBeas Sep 29 '11 at 02:07
  • I must use mysql in production so I have no choice. Did you use sqlite in dev and mysql in production? Is it doable? – Mirko Sep 30 '11 at 11:55
  • Yea, it's the beauty of ORM. You can switch between DB's, just put the gem in your gemfile for the db you want and set the group for development/production. I'm using Sqlite for dev and PG for production, if i want to use mysql i can too. – jBeas Sep 30 '11 at 16:16
0

Try adding this to your Gemfile:

gem 'mysql2', < '0.3'

I made a post about a similar problem a while back. You can view the answer here:

Cannot run migrations due to MySQL error

Community
  • 1
  • 1
Max
  • 15,157
  • 17
  • 82
  • 127
  • 1
    C'mon, you don't really think I didn't add it to my Gemfile. I tried all 0.2.xx mysql2 gems... – Mirko Sep 21 '11 at 10:27