【问题标题】:Installing mysql2 gem for Ruby on Rails with Mac OSX 10.6使用 Mac OSX 10.6 为 Ruby on Rails 安装 mysql2 gem
【发布时间】:2011-07-21 13:16:29
【问题描述】:

我在安装 mysql2 gem 时遇到问题。

当我做gem install mysql2时会出现这个问题:

Marks-MacBook-Pro:~ Mark$ gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
ERROR: Failed to build gem native extension.

/Users/useruser/.rvm/rubies/ruby-1.9.2-p136/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
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
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... 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
    --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=/Users/useruser/.rvm/rubies/ruby-1.9.2-p136/bin/ruby
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mlib
    --without-mlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-zlib
    --without-zlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-socketlib
    --without-socketlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-nsllib
    --without-nsllib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mygcclib
    --without-mygcclib
    --with-mysqlclientlib
    --without-mysqlclientlib


Gem files will remain installed in /Users/useruser/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6 for inspection.
Results logged to /Users/useruser/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/ext/mysql2/gem_make.out

当我使用rails server 时,也会出现:

Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.

【问题讨论】:

    标签: mysql ruby-on-rails ruby osx-snow-leopard gem


    【解决方案1】:

    似乎找不到 MySQL 库。安装 MySQL 了吗?
    尝试通过homebrew安装它:

    brew install mysql
    

    或通过 macports 或 fink 或任何您喜欢的方式安装它。

    然后再试一次:

    gem install mysql2
    

    【讨论】:

    • 谢谢!这行得通!现在,当我启动 Rails 服务器并单击“关于您的应用程序的环境...”时,出现:Mysql2::Error Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) Rails.root: /Users/useruser/example 你知道那是什么意思吗?
    • 你设置mysql服务器运行了吗? “mysql.server start”会完成这项工作,不要忘记为root用户配置访问权限。
    • 这出现了:.错误! pid-file 管理器退出而不更新文件。
    • 在任何操作之前,您必须执行“mysql_install_db”命令并按照说明进行操作
    • 嗨,我遇到了这个问题:imageshack.us/photo/my-images/857/screenshot20110610at230.png 有人可以帮我解决吗?谢谢! :)
    【解决方案2】:

    这个命令对我有用:

    gem install mysql2 -- --srcdir=/usr/local/mysql/include
    

    【讨论】:

    • 如果您使用 mysql 网站提供的二进制文件将其安装在您的 Mac 上,则此选项可以工作。
    • 谢谢你,如上所述,如果你使用mysql网站安装,这可以工作
    • 这对我也有用..但我没有使用 mysql 网站安装。
    • 这对我有用,但我使用了不同的目录。我使用了locate mysql | grep include 并找到了另一个目录。整个命令:gem install mysql2 -v '0.3.21' -- --srcdir=/usr/local/Cellar/mysql/8.0.12/include
    • 我非常爱你
    【解决方案3】:

    以下命令成功地为我工作。

    x.x.x = 您要安装的 mysql2 版本。

    gem install mysql2 -v 'x.x.x' -- --srcdir=/usr/local/mysql/include
    

    【讨论】:

    • 谢谢,在我在 macOS 10.12.5、Ruby 2.3.4、Rails 5.0.3 上安装 MariaDB 10.2(通过 brew)后为我工作
    • 通过自制软件安装的 OSX 10.13.5 和 mysql 的快速说明:--srcdir 为:/usr/local/include/mysql
    【解决方案4】:

    我在 Mac OS X 上不需要 MySQL,因为我在 Vagrant box 上安装了 MySQL。因此,我只是安装了mysql-connector-c。

    brew install mysql-connector-c
    gem install mysql2
    

    【讨论】:

      【解决方案5】:

      以下对我有用

      brew install mysql 
      brew install mysql-connector-c
      gem install mysql2
      

      【讨论】:

        【解决方案6】:

        如果您使用 homebrew 安装 mysql,brew install mysql,这对我有用:

        gem install mysql2 -v 'x.x.x' -- --with-mysql-config=/usr/local/Cellar/mysql/y.y.y/bin/mysql_config
        

        x.x.x = 您要安装的 mysql2 gem 的版本
        y.y.y = 你安装的mysql的版本ls /usr/local/Cellar/mysql可以找到。

        获取mysql的版本

        brew info mysql                                                                                                                                                                                                     
        mysql: stable 5.7.19 (bottled)
                       ...
        /usr/local/Cellar/mysql/5.7.19 (322 files, 233MB) *
        
                       ...
        

        如果你想用 bundle 安装:

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

        【讨论】:

        • 我爱你! '你救了我的命:D
        【解决方案7】:

        修复手动 gem 安装:

        brew install openssl
        gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"
        

        修复所有捆绑包安装:

        brew install openssl
        bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)"
        bundle install
        

        【讨论】:

        • 只有这个对我有用!
        【解决方案8】:

        您必须指定一些额外的环境变量才能在 Mac OSX 10.6 的 64 位架构上安装此 gem:

        env ARCHFLAGS="-arch x86_64" gem install mysql2
        

        如果您使用的是 rvm,您可以在 ~/.rvmrc 文件中将其添加为默认选项:

        rvm_archflags="-arch x86_64"
        

        【讨论】:

        • 没用 :( 可能我做错了,你能详细解释一下怎么做吗?
        • 你得到的是同样的错误还是不同的错误?如果您将 mysql 安装在默认值以外的其他位置,则可能还需要指定其他标志,例如 --with-opt-dir。
        • 我遇到了同样的错误。它说: Gem 文件将继续安装在 /Users/useruser/.rvm/gems/ruby-1.9.2-p136/gems/mysql-2.8.1 中以供检查。也许这有帮助?是的,我正在使用 rvm
        • 在您和 ALoR 的帮助下,我已经解决了问题中的问题。感谢您格式化我的问题! :)
        【解决方案9】:

        我在尝试安装 mysql2 时遇到了完全相同的问题和错误。我认为我的 MySQL 的 mamp 安装可以正常工作,并花了几个小时玩弄路径以使其工作 - 没有成功。

        终于从 ALoR 看到这篇文章并通过自制软件安装了一个新版本 - 但是 - 请务必遵循自制软件的所有说明!我错过了几个步骤,又浪费了一个小时来追踪该问题 - 以下是这些说明: https://stackoverflow.com/a/11061487/1241271

        成功安装 MySQL 后,我运行:sudo gem install mysql2,它就像一个魅力。

        希望这可以帮助某人避免浪费几个小时,因为他们忽略了阅读文档(新错误)。

        【讨论】:

          【解决方案10】:

          确保通过 Homebrew 在 Mac 上安装 openssl。

          brew install openssl
          
          Install mysql2 gem.
          
          gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/i
          

          【讨论】:

            【解决方案11】:

            我知道这已被多次回答,但以下是对我有用的方法: 2019 年 5 月 20 日 OSX 莫哈韦 10.14.4 MySQL Ver 14.14 Distrib 5.7.24,用于 osx10.14 (x86_64),使用 EditLine 包装器 ruby 2.5.0p0(2017-12-25 修订版 61468)[x86_64-darwin17] 导轨 5.2.1

            export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
            gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql\@5.7/5.7.24/bin/mysql_config
            

            将“/usr/local/Cellar/mysql@5.7/5.7.24/bin/mysql_config”更改为您当前的有效路径来自“/usr/local/Cellar/mysql”

            希望这会有所帮助!

            【讨论】:

              【解决方案12】:

              升级到 Catalina (10.15.x) 后我遇到了同样的问题

              我的 Gemfile.lock 定义了 mysql2-0.3.20,我无法安装它。 但是它起作用了,当我将它升级到 mysql2-0.5.2 时

              gem update mysql2 -- --srcdir=/usr/local/include/mysql/
              

              确保你已经用 brew 安装了 mysql。

              brew install mysql
              brew link mysql                                                                                                               
              

              (正在链接 /usr/local/Cellar/mysql/8.0.18...已创建 95 个符号链接)

              然而,在这之后 gem mysql2 被安装了,但是 bundle update mysql2 没有工作。

              但是这个其他答案帮助了我 https://stackoverflow.com/a/39628463/110214

              bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
              
              bundle update mysql2
              

              【讨论】:

                猜你喜欢
                • 2012-02-11
                • 1970-01-01
                • 2011-12-03
                • 2012-05-29
                • 2020-10-12
                • 1970-01-01
                • 2011-07-19
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多