简体   繁体   中英

Rails Error - No Such File to Load — mysql

I've been fighting with a Rails install on my Mac for some time. 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.
  • I've installed the MySQL gem and it appears in the gem list: mysql (2.8.1).
  • I have Passenger installed.
  • The error comes from an existing rails app that works on our production server.
  • Creating a new Rails app, a new MySQL db (using mysqladmin -uroot create sampledb ) works fine.

I've googled this and can't find anything specific to this error. There are a few related results where the solutions relate to paths when installing the 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. There are probably a dozen different versions of the same command floating around out there for 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.

The gem install string that ended up working was this:

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.

  1. Do you have multiple ruby installed? Try invoking this command to find out: whereis ruby
  2. Which ruby version is you passenger using? You can check this from your apache or nginx configuration
  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?

Double check if the mysql bin path is in your $PATH system environment variable. 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. If if this doesn't bring up a list of mysql commands (like mysqladmin etc.) the mysql bin path is not set ccorrectly. You can set it by adding the correct directory to your bash profile file.

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. Important: close and reopen the terminal window to make changes work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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