Rails 服务器无法使用 rvm & 启动 mysql2 OSX 10.6.5 上的 ruby​​ 1.9.2-p0

发布于 2024-10-08 13:14:12 字数 1345 浏览 1 评论 0原文

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

$ 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 use ruby​​-1.9.2-p0 命令之后,我使用以下命令安装了 mysql2:

$ 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捆绑安装完成得很好

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

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

有人有解决这个问题的办法吗?

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

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

作死小能手 2024-10-15 13:14:12

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

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

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

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

这应该保持干净,但也确保任何需要 MySQL 动态库的 gem 或代码都能找到它们。

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

2012 年 7 月参考更新: OS X 10.8 中的更改使得上面的简单方法不太优雅。如果设置该变量,则每次运行 setuid 或 setgid 程序时,您都会在 stderr 上收到此警告:

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

使用 Phusion Passenger Standalone 的 Ruby 开发人员将每五秒在其控制台中看到此消息。它变得非常令人恼火,速度非常快。

我已向 Apple 提交了错误。 OpenRadar 也有。

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

$ brew install mysql

The problem comes from the mysql2 gem missing the dynamic library from 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"

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

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

Reference : http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/

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

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

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

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
不弃不离 2024-10-15 13:14:12

我在这里找到了答案: Mysql 5.5 、雪豹和铁轨

sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle

I found the answer here: Mysql 5.5, Snow leopard and rails

sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
半仙 2024-10-15 13:14:12

在 OS X 10.8 (Mountain Lion) 上,列出的答案都有问题,如答案和评论中所述。

  • 设置 DYLD_LIBRARY_PATH 包含 /usr/local/mysql/lib 会发出来自 OS X 和brew 的警告
  • 使用 install_name_tool 破解 gem 二进制文件每次都需要重做的地方gem 已安装或升级。
  • 切换到brew的mysql可能无法工作;无论如何,我不想重新配置已经工作的安装

一个更简单、更强大的解决方案恕我直言,是将库的链接放在默认的动态库搜索路径中,该路径方便地包括 /usr/local/lib。那是:

ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib

On OS X 10.8 (Mountain Lion), the listed answers all have issues, as noted in the answers and comments.

  • Setting DYLD_LIBRARY_PATH to include /usr/local/mysql/lib gives warnings from OS X and from brew
  • Using install_name_tool to hack where the gem binary looks would need to be redone each time the gem is installed or upgraded.
  • Switch to brew's mysql may not work; and in any case I don't want to reconfigure an already-working installation

A simpler and robust solution IMHO is to put a link to the library in the default dynamic library search path, which conveniently includes /usr/local/lib. That is:

ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib
丢了幸福的猪 2024-10-15 13:14:12

比尔,

弗雷德里克的答案将解决这个问题,但是您可能必须根据版本以及系统上的命名方式更改命令中的某些项目。

例如,在最新版本的 mysql 上 libmysqlclient.16.dylib 实际上是 libmysqlclient.18.dylib。尝试执行以下操作:

locate libmysqlclient.18.dylib

如果没有返回路径,您可以转到:

/usr/local/{your-mysql}/lib

查找文件。然后只需输入 PWD 即可找到该命令的正确目录。

您还需要确定已安装的 rubies 的实际包名称是什么。您可以通过使用找到它

rvm info 

例如,我安装的 1.9.2 是 ruby​​-1.9.2.p180,而不是 ruby​​-1.9.2p0。这也需要在 Frederics 命令中进行更改。

因此,对我来说 Frederic 的命令分别是修复 1.8.7 和 1.9.2 的 rvm rubies:

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.8.7-p334/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle

Bill,

Frederic's answer will solve this problem, however you may have to change some of the items in the command depending on versions and how things are named on your system.

For example, on the most recent version of mysql libmysqlclient.16.dylib is actually libmysqlclient.18.dylib. Try doing a:

locate libmysqlclient.18.dylib

If that does not return the path you can go to:

/usr/local/{your-mysql}/lib

to find the file. Then just a PWD to find the correct directory for the command.

You will also need to determine what the actual package names of the rubies you have installed are. You can find this by using

rvm info 

For example, my installation of 1.9.2 is ruby-1.9.2.p180, not ruby-1.9.2p0. This will need to be changed in Frederics command as well.

So, for me Frederic's command became for fixing the rvm rubies for 1.8.7 and 1.9.2, respectively:

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.8.7-p334/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql-5.5.10-osx10.6-x86_64/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
许久 2024-10-15 13:14:12

以下通过: http://lightyearsoftware.com/2011 /02/mysql-5-5-on-mac-os-x/

2012 年 7 月更新:

OS X 10.8 中的更改使得上面的简单方法不太优雅。如果设置该变量,则每次运行 setuid 或 setgid 程序时,您都会在 stderr 上收到此警告:

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

使用 Phusion Passenger Standalone 的 Ruby 开发人员将每五秒在其控制台中看到此消息。它变得非常令人恼火,速度非常快。

我已向 Apple 提交了错误。 OpenRadar 也有。

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

$ brew install mysql

below via: http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/

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

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

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

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
酷到爆炸 2024-10-15 13:14:12

我在这个问题上停留了一段时间,并得出了不同的解决方案。

请注意缺少的库是版本 16

库未加载:libmysqlclient.16.dylib(LoadError)

原来我有该库的版本 20 - libmysqlclient.20.dylib

我正确地在我的库中有 gem 'mysql2' Gemfile,但我需要做的是卸载gem,gem uninstall mysql(我安装了多个版本的gem),然后执行新的bundle install来获取< em>正是我需要这个库的版本。

之后,它查找并找到了该库的正确版本。

I was stuck on this for a while and came to a different solution.

Notice how the missing library is version 16:

Library not loaded: libmysqlclient.16.dylib (LoadError)

Turns out I had version 20 of that library - libmysqlclient.20.dylib

I correctly had gem 'mysql2' in my Gemfile, but what I needed to do was uninstall the gem, gem uninstall mysql (I had multiple versions of the gem installed) and then doing a new bundle install to get just the version I needed of this library.

After that it looked for - and found - the correct version of that lib.

悲歌长辞 2024-10-15 13:14:12

我的位于不同的位置,我必须使用:

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle.

Mine was in a different location, I had to use:

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle.
剑心龙吟 2024-10-15 13:14:12

将 mysql 升级到最新版本并重新安装 mysql2 gem 对我有用
brew升级mysql
gem 卸载 mysql2
gem install mysql2

顺便说一句:我的MySQL版本是5.7.18,mysql2 gem版本是0.4.5

Upgraded mysql to latest version and reinstall mysql2 gem works to me
brew upgrade mysql
gem uninstall mysql2
gem install mysql2

BTW: My MySQL version is 5.7.18, mysql2 gem version is 0.4.5

红焚 2024-10-15 13:14:12

这就是我所做的(与其他人类似)

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.10/lib/mysql2/mysql2.bundle

Here is what I do (similar to others)

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.10/lib/mysql2/mysql2.bundle
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文