简体   繁体   English

Rails错误-没有要加载的此类文件-MySQL

[英]Rails Error - No Such File to Load — mysql

I've been fighting with a Rails install on my Mac for some time. 我一直在为Mac上的Rails安装而斗争。 The error I'm getting (in my development log) says: 我收到的错误(在我的开发日志中)说:

Status: 500 Internal Server Error no such file to load -- mysql

Here's some info: 这是一些信息:

  • I can successfully rake db:migrate my application. 我可以成功耙db:migrate我的应用程序。
  • I've installed the MySQL gem and it appears in the gem list: mysql (2.8.1). 我已经安装了MySQL gem,它显示在gem列表中:mysql(2.8.1)。
  • I have Passenger installed. 我已经安装了乘客。
  • The error comes from an existing rails app that works on our production server. 该错误来自可在我们的生产服务器上运行的现有Rails应用。
  • Creating a new Rails app, a new MySQL db (using mysqladmin -uroot create sampledb ) works fine. 创建一个新的Rails应用程序,一个新的MySQL数据库(使用mysqladmin -uroot create sampledb )可以正常工作。

I've googled this and can't find anything specific to this error. 我已经在Google上进行了搜索,但找不到与此错误相关的任何内容。 There are a few related results where the solutions relate to paths when installing the MySQL gem. 在安装MySQL gem时,有一些与结果相关的解决方案与路径相关的信息。 For example, 例如,

sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
  --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
  --with-mysql-include=/usr/local/mysql/include

Has anyone else experienced this issue or suggest a solution? 其他人是否遇到过此问题或建议解决方案?

Thanks for the response - the good news is, the problem is solved. 感谢您的答复-好消息是,问题已解决。

The bad news - I'm not entirely sure what fixed it. 坏消息-我不完全确定是什么原因解决了。 I can tell you this: it had something to do with the mysql gem install and all the flags pointing to lib, include and config. 我可以告诉你:这与mysql gem install和所有指向lib,include和config的标志有关。 There are probably a dozen different versions of the same command floating around out there for Mac OS X Leopard. 对于Mac OS X Leopard,该命令可能有十几种不同版本。

The odd thing was that ruby appeared to be connected to mysql on some level (it's ability to rake db for example) but broke when actually loading a page. 奇怪的是,ruby似乎在某种程度上已连接到mysql(例如,它具有耙入db的能力),但在实际加载页面时却损坏了。

The gem install string that ended up working was this: 最终可以工作的gem install字符串是这样的:

sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

I'd love some clarification on the how's & why's of this. 我希望对此做些什么以及为什么做些澄清。 This worked for me, but doesn't include pointers to the app directory, the lib directory or the include directory. 这对我有用,但不包含指向应用程序目录,lib目录或包含目录的指针。

  1. Do you have multiple ruby installed? 您是否安装了多个红宝石? Try invoking this command to find out: whereis ruby 尝试调用此命令以找出: whereis ruby
  2. Which ruby version is you passenger using? 您的乘客使用哪种红宝石版本? You can check this from your apache or nginx configuration 您可以从apache或nginx配置中进行检查
  3. Is the ruby version passenger is using the same as ruby you are using from the command line? 红宝石版本的乘客使用的命令行与您在命令行中使用的红宝石版本相同吗?
  4. Is mysql gem installed on that ruby version? 在该ruby版本上安装了mysql gem吗?

Double check if the mysql bin path is in your $PATH system environment variable. 仔细检查mysql bin路径是否在$ PATH系统环境变量中。 If you execute 如果执行

*echo $PATH* 

there must be displayed something like 必须显示类似

*/usr/local/mysql/bin*

You can also type 您也可以输入

mysql and then the tab-key twice. mysql ,然后按两次tab键。 If if this doesn't bring up a list of mysql commands (like mysqladmin etc.) the mysql bin path is not set ccorrectly. 如果这不能显示mysql命令列表(如mysqladmin等),则说明mysql bin路径设置不正确。 You can set it by adding the correct directory to your bash profile file. 您可以通过将正确的目录添加到bash配置文件中来进行设置。

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile

Please verify up front if 请预先验证是否

*/usr/local/mysql/bin* 

really contains the mysql commands on your Mac. 实际上包含Mac上的mysql命令。 Important: close and reopen the terminal window to make changes work. 重要:关闭并重新打开终端窗口以使更改生效。

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

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