【问题标题】:gem install mysql failgem安装mysql失败
【发布时间】:2011-08-13 07:28:04
【问题描述】:

我已按照 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​​ 非常陌生......

美国东部时间 2011 年 4 月 26 日下午 5:11 更新 安装 RVM 并将 ruby​​ 更新到 1.9.2 我还浏览了 cmets 上发布的链接。我做了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.

真的很想感谢那些评论的人......如果能提供更多帮助真的很感激......已经尝试安装该死的mysql 2天......

【问题讨论】:

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


【解决方案1】:

如果你愿意,你可以尝试一种完全不同的方法,使用 homebrew 安装 mysql:

https://github.com/mxcl/homebrew

然后尝试基于此安装 gem。

【讨论】:

  • 我已经安装了自制软件。你能告诉我如何用它安装mysql gem吗?我正在阅读有关 Gems、Eggs 和 Perl 模块的 wiki。它并没有解释太多......
【解决方案2】:

试试这个:

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

【讨论】:

  • 给 mac 用户的提示:使用 finder 并执行“转到文件夹”来查找您的 mysql 安装。找到配置文件后,将 mysql_config 图标从 finder 拖到终端中,以在终端窗口中显示路径
  • 对于 homebrew 0.9.4 路径是 /usr/local/Cellar/mysql/&lt;version&gt;/bin,但它仍然不适合我...
  • 我同意金牌!我也添加了rails:bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql55/5.5.49/bin/mysql_config
【解决方案3】:

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

希望这对和我有同样问题的其他人有所帮助..

【讨论】:

    【解决方案4】:

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

     yum install mysql mysql-server mysql-devel
    

    【讨论】:

      【解决方案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,使用 homebrew 安装了 MySQL。

      【讨论】:

      • 非常感谢!搞砸了 3 个小时后,这是唯一有帮助的东西!
      • 同样对我有用。我还通过 RVM 使用 Ruby (1.9.3),通过 brew 使用 MySQL。
      【解决方案6】:

      当前未安装程序“mysql_config”。 您可以通过键入来安装它:

      $ sudo apt-get install libmysqlclient-dev
      $ bundle install
      
      bundle show [mysql2] # To find the location.
      

      【讨论】:

        【解决方案7】:

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

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

        bundle config man page

        【讨论】:

          【解决方案8】:

          截至 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
          

          如果您仍然有问题,请在安装 gem 之前尝试以下操作

          export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
          

          【讨论】:

            【解决方案9】:

            按照以下步骤进行

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

            【讨论】:

              猜你喜欢
              • 2018-11-27
              • 1970-01-01
              • 2013-02-24
              • 2012-09-26
              • 2013-06-26
              • 1970-01-01
              • 1970-01-01
              • 2010-11-24
              • 2020-02-17
              相关资源
              最近更新 更多