我在 OS X Lion 上使用 MAMP2、rvm,我无法让 mysql2 gem 与我的 Rails 应用程序一起使用。
我关注了这篇博文 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
这些是步骤:
$ 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 'make -j 3' 中对 'my_atomic-t.dir' 的单元测试进行评论后,一切正常。
$ 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
我猜“客户未知”警告并不重要。
最后一步:
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 服务器时遇到的错误:
$ 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 出现无数错误之后,这就是我完全陷入困境的地方。
我在带有 MAMP 2.0.3 和 Rails 3.0.7 的 OS X Lion 上使用 RVM 和 ruby-1.9.2-p290。
非常感谢任何帮助!