Rails服务器无法使用rvm&在MySQL2上启动OSX 10.6.5上的ruby 1.9.2-p0 [英] rails server fails to start with mysql2 using rvm & ruby 1.9.2-p0 on OSX 10.6.5

查看:70
本文介绍了Rails服务器无法使用rvm&在MySQL2上启动OSX 10.6.5上的ruby 1.9.2-p0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动Rails服务器时出现以下错误:

I'm getting the following error when I start rails server:

$ rails server
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2.rb:7:in `require':     dlopen(/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError) 
Referenced from: /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2- 0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-    
0.2.6/lib/mysql2/mysql2.bundle

在rvm使用ruby-1.9.2-p0命令后,我已经使用以下命令安装了mysql2:

I've installed mysql2 with the following command after the rvm use ruby-1.9.2-p0 command:

$ gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions.  This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known

我的Gemfile以及database.yml文件中都有mysql2,并且捆绑安装完成了

I have mysql2 in my Gemfile as well as in the database.yml file and bundle install completes fine

$ bundle show mysql2
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6

我知道Rails服务器错误是由于它不知道OSX上的mysql_config位置,但是在gem install上我指定了正确的位置.然而,RVM的瑰宝似乎并不尊重mysql_config的位置.

I understand the rails server error is due to it not knowing the mysql_config location on OSX, however on gem install I specified the correct location. Yet RVM's gem is not respecting that mysql_config location it seems.

有人对此有解决方案吗?

Anyone have a solution to this?

推荐答案

问题来自mysql2 gem缺少MySQL的动态库.

The problem comes from the mysql2 gem missing the dynamic library from MySQL.

install_name_tool ...更干净的解决方案将需要更新您的DYLD_LIBRARY_PATH以向其中添加MySQL库.为此,请更新您的~/.bash_profile以添加MySQL库文件夹:

A cleaner solution than install_name_tool ... would need to update your DYLD_LIBRARY_PATH to add MySQL libs to it. To do so, update your ~/.bash_profile to add the MySQL library folder :

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

注意:您可能要根据您的安装来更新MySQL位置

Note: You might want to update the MySQL location based on your install

这应该保持环境整洁,但还应确保需要MySQL动态库的所有gem或代码都能找到它们.

This should keep things clean but also ensure that any gem or code requiring MySQL dynamic libraries will find them.

参考资料: http://lightyearsoftware.com /2011/02/mysql-5-5-on-mac-os-x/

参考更新2012年7月::OS X 10.8中的更改使上述简单方法不太美观.如果设置了该变量,则每次运行setuid或setgid程序时,都会在stderr上收到以下警告:

Reference Update July 2012: A change in OS X 10.8 makes the easy method above less elegant. If you set that variable, every time you run a setuid or setgid program, you get this warning on stderr:

dyld: DYLD_ environment variables being ignored because main executable (...) is setuid or setgid

使用Phusion Passenger Standalone的Ruby开发人员将每五秒钟看到此消息在其控制台中显示一次.真的很烦人,很快.

Ruby developers using Phusion Passenger Standalone will see this message displayed in their console every five seconds. It gets really irritating, very fast.

我已向Apple提出了错误.它也在OpenRadar中.

I have filed a bug with Apple. It’s also at OpenRadar.

同时,还有第三种解决客户端库路径问题的方法,该方法不需要设置DYLD_LIBRARY_PATH(解决此10.8问题)或使用install_name_tool入侵.bundle文件:

In the meantime, there is also a third way to fix the client library path problem that doesn’t require setting DYLD_LIBRARY_PATH (working around this 10.8 issue) or hacking .bundle files with install_name_tool:

$ brew install mysql

这篇关于Rails服务器无法使用rvm&在MySQL2上启动OSX 10.6.5上的ruby 1.9.2-p0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆