Rails、MySQL 和 Snow Leopard

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/991708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:29:54  来源:igfitidea点击:

Rails, MySQL and Snow Leopard

mysqlruby-on-railsrubyosx-snow-leopard

提问by coneybeare

I upgraded to Snow Leopard using the disc we got at WWDC.

我使用我们在 WWDC 上获得的光盘升级到 Snow Leopard。

Trying to run some of my rails apps now complains about sql

尝试运行我的一些 Rails 应用程序现在抱怨 sql

    (in /Users/coneybeare/Projects/Ambiance/ambiance-server)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
Importing all sounds in /Users/coneybeare/Projects/Ambiance/ambiance-sounds/Import 32/Compressed/

 -- AdirondackPeepers.caf
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
dlopen(/opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle, 9): Library not loaded: /usr/local/mysql/lib/libmysqlclient.16.dylib
  Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle
  Reason: image not found - /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle

(See full trace by running task with --trace)

I could have sworn I fixed this once before. The problem is that

我可以发誓我以前解决过这个问题。问题是

sudo gem install mysql

does not work and gives the error:

不起作用并给出错误:

 Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
    ERROR: Failed to build gem native extension.

/opt/local/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no


Gem files will remain installed in /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

Has anybody gotten mysql to work with rails on snow leopard yet? If so, what is your setup and better yet, what can I do to reproduce it?

有没有人让 mysql 与雪豹上的导轨一起工作?如果是这样,你的设置是什么,更好的是,我能做些什么来重现它?

回答by Ian Selby

I just went through the same pain... here's what worked for me:

我刚刚经历了同样的痛苦......这对我有用:

  1. Download / install the 64-bit MySQL 5.1.37 from mysql.com
  2. run the following commands:
  1. 从 mysql.com 下载/安装 64 位 MySQL 5.1.37
  2. 运行以下命令:
    sudo gem update --system

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

I also uninstalled all mysql gems that were floating around from my 10.5 days, that may do it if the above doesn't work for you :)

我还卸载了从我的 10.5 天开始漂浮的所有 mysql gem,如果上述方法对您不起作用,则可能会这样做:)

回答by Shebanator

Rebuilding mysql as 64bit or installing the 64bit version is important, but you also need to make sure you build the native parts of the mysql gem as 64bit as well (this doesn't apply if you are on one of the original Intel Core Duo macs).

将 mysql 重建为 64 位或安装 64 位版本很重要,但您还需要确保将 mysql gem 的本机部分也构建为 64 位(如果您使用的是原始 Intel Core Duo mac 之一,则这不适用)。

Here's the magic command:

这是魔术命令:

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

You should set the ARCHFLAGS as shown above whenever you do a gem install with native components on Snow Leopard.

每当您在 Snow Leopard 上使用本机组件进行 gem 安装时,您都应该按照上图所示设置 ARCHFLAGS。

回答by Steven Soroka

If you're using bundler, you can use "bundle config" to set the proper build arguments for mysql like so:

如果您使用的是 bundler,则可以使用“bundle config”为 mysql 设置正确的构建参数,如下所示:

bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config

回答by Sam Soffes

I fought with this for a long time and finally got it working on Snow Leopard. I ended up installing Ruby, RubyGems, and MySQL from source (see the Hivelogic tutorialfor installing Ruby and RubyGems. The MySQL tutorial is linked at the bottom). I finally got the gem to install, but I was still getting

我为此奋斗了很长时间,终于让它在 Snow Leopard 上工作。我最终从源代码安装了 Ruby、RubyGems 和 MySQL(请参阅Hivelogic 教程以安装 Ruby 和 RubyGems。MySQL 教程链接在底部)。我终于安装了 gem,但我仍然得到

dyld: lazy symbol binding failed: Symbol not found: _mysql_init
  Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
  Expected in: flat namespace

dyld: Symbol not found: _mysql_init
  Referenced from: /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle
  Expected in: flat namespace

Trace/BPT trap

I finally deleted the mysql.bundle(I have no idea what this is for) and it all worked.

我终于删除了mysql.bundle(我不知道这是为了什么)并且一切正常。

sudo rm -f /Library/Ruby/Site/1.8/universal-darwin10.0/mysql.bundle

Hope that helps someone.

希望能帮助某人。

回答by Ryan Oberoi

I have seen this problem many times. almosteverytime I build mysql on a machine. I think, you have to pass your mysqlconfig as part of the gem install command.

我已经多次看到这个问题。几乎每次我在机器上构建 mysql 时。我认为,您必须将 mysqlconfig 作为 gem install 命令的一部分传递。

sudo gem install mysql -- --with-mysql-config=/your/mysql/config

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby
--with-mysql-config

Remember that you need mysql dev files to be able to build this gem.

请记住,您需要 mysql dev 文件才能构建此 gem。

回答by Ryan Oberoi

I was having problems with getting my configuration to work after installing snow leopard. I found MAMP at http://www.mamp.infoand it bundles Apache, PHP and MySQL. you install it like an application and it just works. Maybe worth giving it a try, and it is free.

安装雪豹后,我在使配置正常工作时遇到问题。我在http://www.mamp.info找到了 MAMP,它捆绑了 Apache、PHP 和 MySQL。您像应用程序一样安装它,它就可以正常工作。也许值得一试,而且它是免费的。

mesh

回答by bratsche

The instructions for setting ARCHFLAGS and passing --mysql-config=... didn't seem to be quite enough to solve this for me on Snow Leopard. In addition to doing that, I added:

设置 ARCHFLAGS 和传递 --mysql-config=... 的说明似乎不足以在 Snow Leopard 上为我解决这个问题。除此之外,我补充说:

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

to my bash profile, and this solved it for me.

到我的 bash 配置文件,这为我解决了这个问题。

回答by ohho

In case you prefer homebrew, instead of installing MySQL manually.

如果您更喜欢 home brew,而不是手动安装 MySQL。

Un-install the existing mysql gem (if any):

卸载现有的 mysql gem(如果有):

 sudo gem uninstall mysql 

Locate the ‘mysql_config' file:

找到“mysql_config”文件:

 find /usr -name 'mysql_config' 

Re-install mysql gem:

重新安装 mysql gem:

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

Note:replace /usr/local/bin/with the corresponding mysql_configpath found in step 2. Also on my blog.

注意:替换/usr/local/bin/mysql_config步骤 2 中找到的相应路径。也在我的博客上

回答by Ricky McMillen

Ian Selby thank you alot but I had to remove the sudofrom in front of sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

伊恩塞尔比非常感谢你,但我不得不sudo从前面删除sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

I was installing to a gemset and am using rvm which I think asks you not to use the sudo keyword. Thanks alot.

我正在安装到 gemset 并使用 rvm,我认为它要求您不要使用 sudo 关键字。非常感谢。

回答by surajit dey

I've solved it this way:

我是这样解决的:

  1. after install dmg file of mysql  
  2. bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin//mysql_config
  3. env ARCHFLAGS="-arch x86_64"
  4. bundle install
  1. 安装mysql的dmg文件后  
  2. 捆绑配置 build.mysql --with-mysql-config=/usr/local/mysql/bin//mysql_config
  3. 环境 ARCHFLAGS="-arch x86_64"
  4. 捆绑安装