简体   繁体   English

无法在Lion,Rails3应用程序上使用mysql2 gem与MAMP2和RVM一起使用

[英]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. 我在OS X Lion上使用MAMP2,rvm,我无法使用mysql2 gem来使用我的Rails应用程序。

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 我已经关注了这篇博客文章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

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. 在/tmp/mysql-5.5.9/CMakeFiles/Makefile2中对'my_atomic-t.dir'进行单元测试后,make -j 3'就可以了。

$ 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服务器时出现的错误:

$ 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. 我只是无法设置mysql2 gem并且我已经尝试了几周。 After numerous errors trying to install mysql2 gem, this is where I'm completely stuck. 在尝试安装mysql2 gem之后出现了很多错误,这就是我完全陷入困境的地方。

I am using RVM and ruby-1.9.2-p290 on OS X Lion with MAMP 2.0.3 and Rails 3.0.7. 我在OS X Lion上使用RVM和ruby-1.9.2-p290,使用MAMP 2.0.3和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. 我解决了这个问题卸载mysql-connector-c并使用brewed mysql服务器中的include和lib标志重新编译mysql2 gem。

$ 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/ http://abisso.org/2012/03/failed-to-allocate-memory/

You should not use MAMP for this. 你不应该使用MAMP。

I read what you are trying to do. 我读了你要做的事。 Your problem is not the mysql2 gem. 你的问题不是mysql2的宝石。 Your problem is your installation of mysql. 你的问题是你的mysql安装。

Follow this article showing using homebrew to install mysql. 按照本文显示使用自制软件安装mysql。 It is very simple and takes about 10-15 minutes including install time to get it setup. 它非常简单,大约需要10-15分钟,包括安装时间来安装它。

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

Side note with using brew to install mysql. 使用brew安装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... 安装mysql后它会成功,它会吐出大量信息,你需要仔细查看它,因为在所有其他垃圾中有1-2条线路是指令,粘贴一些东西等等......

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). 目前在我的设置中我有MAMP(对于我的/ sites目录)在做wordpress网站等简单的东西时...然后我有我的自制的mysql for rails(最终我切换到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. 我有这个设置因为我的项目要求我在rails应用程序,静态html登陆页面和一些较旧的php项目之间跳转,我喜欢分离有2个mysql安装。

Try adding this to your Gemfile: 尝试将此添加到您的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 由于MySQL错误导致无法运行迁移

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM