问题描述
我在OS X Lion上使用的是MAMP2,rvm,并且无法让mysql2 gem与我的Rails应用一起使用.
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.
我已关注此博客文章 http://blog.mirotin.net/35/mamp-1-9-5-mysql-5-5-9-and-ruby-mysql2 和这一个 http://www.pa-ket. com/blog/show/12-osx-ruby-mysql2-gem-python-mysqldb-using-mamp
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
这些步骤是:
$ 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
此步骤失败:
$ make -j 3
在对/tmp/mysql-5.5.9/CMakeFiles/Makefile2中的'my_atomic-t.dir'进行单元测试后,'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
以及启动Rails服务器时出现的错误:
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
我只是无法设置mysql2 gem,我已经尝试了好几个星期.在尝试安装mysql2 gem时发生了许多错误之后,这是我完全被卡住的地方.
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.
我在带有MAMP 2.0.3和Rails 3.0.7的OS X Lion上使用RVM和ruby-1.9.2-p290.
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!
推荐答案
我解决了这个问题,即从酿造的mysql服务器上卸载mysql-connector-c并使用include和lib标志重新编译mysql2 gem.
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/
这篇关于无法在Lion,Rails3应用程序上使mysql2 gem与MAMP2和RVM一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!