【问题标题】:How do I install mysql2 gem under Ruby 1.9.3? Works under 2.0.0如何在 Ruby 1.9.3 下安装 mysql2 gem?在 2.0.0 下工作
【发布时间】:2013-06-25 16:55:51
【问题描述】:

在我的机器上安装 mysql2 gem 时遇到问题。

我有带有最新 Xcode 的 OS X 10.8,并通过 Homebrew 安装了 mySql。所有 rubies 都使用最新的 RVM 安装。

我可以在ruby 2.0.0-p195下很好地安装mysql2

[~]$ rvm use 2.0.0                                                              [ruby-1.9.3-p429]
Using /Users/aselder/.rvm/gems/ruby-2.0.0-p195
[~]$ gem in mysql2                                                              [ruby-2.0.0-p195]
Fetching: mysql2-0.3.11.gem (100%)
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed

在Ruby 1.9.3和1.8.7下,找不到mysql.h文件

    [~]$ rvm use 1.9.3                                                              [ruby-1.9.3-p429]
    Using /Users/aselder/.rvm/gems/ruby-1.9.3-p429
    [~]$ gem in mysql2                                                              [ruby-1.9.3-p429]
    Fetching: mysql2-0.3.11.gem (100%)
    Building native extensions.  This could take a while...
    ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

            /Users/aselder/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb
    checking for rb_thread_blocking_region()... yes
    checking for rb_wait_for_single_fd()... yes
    checking for mysql.h... no
    checking for mysql/mysql.h... no
    -----
    mysql.h is missing.  please check your installation of mysql and try again.
    -----
    *** 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=/Users/aselder/.rvm/rubies/ruby-1.9.3-p429/bin/ruby
        --with-mysql-config
        --without-mysql-config


    Gem files will remain installed in /Users/aselder/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.11 for inspection.
    Results logged to /Users/aselder/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.11/ext/mysql2/gem_make.out

我还尝试了各种命令行选项来让 gem 找到 mysql 安装:

例如 gem install mysql2 -- --with-mysql-config=/usr/local/opt/mysql/bin/mysql_config

【问题讨论】:

  • 我遇到了同样的问题,但我一直无法弄清楚
  • 我遇到了完全相同的问题。我在一台全新的机器上(10.8)。 Ruby 2.0 没有问题,1.9.2 和 1.9.3 抱怨缺少 mysql.h。
  • 你的 MySQL 版本是多少?我使用 5.6.12 遇到了同样的问题。卸载它并安装 5.6.10 解决了这个问题。

标签: ruby bundler homebrew mysql2


【解决方案1】:

我找到了这个答案,它解决了我的问题: Error installing mysql2: Failed to build gem native extension

引用:

在 Ubuntu/Debian 和其他使用 aptitude 的发行版上:

sudo apt-get install libmysql-ruby libmysqlclient-dev

在 Red Hat/CentOS 和其他使用 yum 的发行版上:

sudo yum install mysql-devel

在带有 Homebrew 的 Mac OS X 上:

brew install mysql

我在 debian 上,运行上述命令后,我运行了:

gem install mysql2

它确实有效。

【讨论】:

    【解决方案2】:

    我解决了在启动 mysql 服务器的情况下安装 gem 的问题!

    brew install mysql
    
    mysql.server start
    
    bundle install
    

    在 ruby​​-1.9.3-p125 下。

    希望对你有帮助

    【讨论】:

      【解决方案3】:

      尝试使用 Homebrew 安装 mysql,使用 Bundler 安装 mysql2 gem。

      brew update
      brew install mysql
      

      将以下内容添加到您的Gemfile

      gem "mysql2"
      

      运行:

      bundle install
      

      【讨论】:

      【解决方案4】:

      我通过自制软件将 mysql 从 5.6 降级到 5.5 解决了这个问题。无法提供更详细的解释,但已解决。

      【讨论】:

      • 我会试试这个。谢谢。
      • 我现在遇到同样的问题,正在使用 5.5.31
      【解决方案5】:

      对此我有一个非常愚蠢的解决方案:我打开 Xcode 并接受了许可协议。更新下载了一个新版本,在手动接受新协议之前我无法编译任何东西。

      【讨论】:

        猜你喜欢
        • 2013-02-18
        • 2013-04-24
        • 2013-10-01
        • 2011-05-06
        • 2011-04-09
        • 1970-01-01
        • 2012-04-05
        相关资源
        最近更新 更多