Can't get mysql2 gem to work with MAMP2 and RVM on Lion, Rails3 app
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 shutdo开发者_C百科wn 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!
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/
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.
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
精彩评论