gem install mysql失败

时间:2011-04-26 19:15:33

标签: mysql ruby-on-rails ruby macos rubygems

我已按照http://geryit.com/blog/2011/01/installing-mysql-with-rails-on-mac-os-x-snow-leopard/上的说明操作,包括通过macport安装ruby。

每当我执行 gem install mysql 时,我都会收到以下错误

bash-3.2# gem install mysql
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
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-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=/opt/local/bin/ruby
    --with-mysql-config
    --without-mysql-config


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

如何解决此问题?我已经使用包文件(.pkg)安装了32位mysql,而且,我对ruby非常新...

更新4/26/11美国东部时间下午5:11 已安装RVM并更新了ruby到1.9.2 另外,我查看了评论中发布的链接。我做了locate mysql_config 结果是

/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config
/usr/local/mysql-5.1.56-osx10.6-x86/man/man1/mysql_config.1

因此,我试过了 gem install mysql - -with-mysql-config=/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config 但它仍然不起作用......但我确实得到了新的错误信息..

/Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:435:in `try_link0'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:440:in `try_link'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:552:in `try_func'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:797:in `block in have_func'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
    from /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/mkmf.rb:796:in `have_func'
    from extconf.rb:50:in `<main>'


Gem files will remain installed in /Users/kyle/.rvm/rubies/ruby-1.9.2-p180/bin/th-mysql-config=/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config/gems/mysql-2.8.1 for inspection.

真的要感谢那些评论过的人......非常感谢能给予更多的帮助.....一直试图安装这个darn mysql 2天......

9 个答案:

答案 0 :(得分:17)

目前尚未安装程序'mysql_config'。 您可以输入以下命令安装它:

$ sudo apt-get install libmysqlclient-dev
$ bundle install

bundle show [mysql2] # To find the location.

答案 1 :(得分:11)

试试这个:

gem install mysql -- --with-mysql-config=/usr/local/mysql-5.1.56-osx10.6-x86/bin/mysql_config

(注意额外的破折号)

如果这不起作用,我强烈建议您使用MySQL上面提到的自制安装。你可以在这里阅读关于汤到坚果的安装:Uninstall Ruby on Rails on Mac OS X 10.6

答案 2 :(得分:9)

我在Cent OS中遇到了同样的问题,但是通过安装mysql-devel

解决了这个问题
 yum install mysql mysql-server mysql-devel

答案 3 :(得分:5)

基于this answer我最终编辑了我的/usr/local/Cellar/mysql/5.6.12/bin/mysql_config文件以删除-Wno-null-conversion -Wno-unused-private-field,这就是mkmf.log抱怨的错误。

我的设置是Mac OSX,使用RVM安装Ruby,使用自制软件安装MySQL。

答案 4 :(得分:4)

通过卸载我的系统上的32位MySQL解决了这个问题..并安装了64.5位5.1.56。

希望这对那些和我有同样问题的人有所帮助。

答案 5 :(得分:3)

如果您使用bundler,则可以使用bundle config为您的宝石设置构建参数,这会将您的构建选项保存到~/.bundle/config,以便下次需要构建时你的宝石,配置选项已经设定,例如:

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

bundle config man page

答案 6 :(得分:2)

如果您愿意,可以尝试使用自制软件安装mysql的完全不同的方法:

https://github.com/mxcl/homebrew

然后尝试根据它安装gem。

答案 7 :(得分:2)

从2018年11月开始适用于Mac

gem install mysql2 -v '0.4.8' -- --with-ldflags=-L/usr/local/opt/mysql@5.7/lib --with-cppflags=-I/usr/local/opt/mysql@5.7/include

答案 8 :(得分:0)

按照以下步骤

  1. sudo apt-get 更新
  2. sudo apt-get install mysql-client libmysqlclient-dev
  3. gem 安装 mysql2