【问题标题】:bundle install problem: mysql.h is missing捆绑安装问题:缺少 mysql.h
【发布时间】:2011-08-20 15:43:36
【问题描述】:

在我的 mac OSX 10.6 32 位中,我可以很容易地安装 mysql2 gem,但不能在 mini mac 10.6 64 位服务器中。

我在麻烦的服务器上安装了 MySQL 5.5.11,而在我家的 mac MySQL 5.5.0.m2 不知何故,当我运行捆绑安装时,它在服务器上尝试安装 mysql2.0.3.2 而在家里 mysql2.0.2.6

请不要告诉我

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

我试过了,不行。

在 $PATH 中包含 /usr/local/mysql/bin 也无济于事。

错误代码:

    Installing mysql2 (0.3.2) with native extensions /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:533:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

        /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... 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
    --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/administrator/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
    --with-mysql-config
    --without-mysql-config


Gem files will remain installed in /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2 for inspection.
Results logged to /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.3.2/ext/mysql2/gem_make.out
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:511:in `block in build_extensions'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `each'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:486:in `build_extensions'
    from /Users/administrator/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:159:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/source.rb:96:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:55:in `block in run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `block in each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/spec_set.rb:12:in `each'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:44:in `run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/installer.rb:8:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/cli.rb:225:in `install'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor.rb:246:in `dispatch'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/lib/bundler/vendor/thor/base.rb:389:in `start'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.12/bin/bundle:13:in `<top (required)>'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/bin/bundle:19:in `load'
    from /Users/administrator/.rvm/gems/ruby-1.9.2-p180/bin/bundle:19:in `<main>'

【问题讨论】:

    标签: ruby-on-rails-3 bundler mysql2


    【解决方案1】:

    验证 gcc 是否已安装。如果不是,您将收到同样的错误消息。

    您可以检查它提到的结果/日志文件以获取有关原因的更多线索。

    【讨论】:

    • 原来我在我的 archflag 命令中错误地添加了一个空格键。
    【解决方案2】:

    好吧,我的解决方案是:

    $ sudo brew install mysql
    
    $ sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
      --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
      --with-mysql-include=/usr/local/mysql/include
    

    来源:http://wonko.com/post/how-to-install-the-mysqlruby-gem-on-mac-os-x-leopard

    或者:

    $sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \
      --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
      --with-mysql-include=/usr/local/mysql/include
    

    如果你的mysql版本是64Bits

    在那之后我遇到了很多问题,因为如果我想创建数据库:

    $: bundle exec rake db:reset
    

    我收到了这个错误:

    dyld: lazy symbol binding failed: Symbol not found: _mysql_init
      Referenced from: /Users/workdreamer/Sites/cavortify/implementation/cavortify/mysql/ruby/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
      Expected in: flat namespace
    
    dyld: Symbol not found: _mysql_init
      Referenced from: /Users/workdreamer/Sites/cavortify/implementation/cavortify/mysql/ruby/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle
      Expected in: flat namespace
    

    解决方案是:在你的 gemfile 中添加:gem "ruby-mysql"

    好的,用一天半的时间找到解决方案。

    祝你有美好的一天!

    【讨论】:

    • 你不需要 sudo brew
    • ruby-mysql 不使用你构建的原生文件。
    【解决方案3】:

    此方法适用于 64 位机器上的 Rails 3.1.0(希望是更高版本)。我在 Ruby-1.9.2-p180 上使用过。

    本博客回答:http://www.tatvartha.com/2010/10/installing-mysql-gem-with-bundler-on-snow-leopard/

    基本上就是上面的方法: $ sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

    可以工作,但没有捆绑器。

    要使用捆绑器,首先必须在终端上运行它:

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

    请注意“mysql2”而不是该博客中显示的“mysql”。

    这会将配置添加到 ~/.bundle/config 文件中

    然后将其添加到 ~/.bash_profile:

    export ARCHFLAGS="-arch x86_64"
    

    这与告诉 bundler 在这篇文章的顶部运行命令是一样的。

    【讨论】:

    • 只是一个小提示:因为我使用 Homebrew 安装 Mysql,所以该行应该如下所示: bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql/ 5.5.20/bin/mysql_config
    • 或者你可以找到它像 $ find / -name mysql_config 2&gt;/dev/null
    【解决方案4】:

    我可以让它工作的唯一方法是安装 x64 版本的 mysql。我刚刚使用了位于http://dev.mysql.com/downloads/mysql/ 的 .dmg,它就像一个魅力。希望我能把解决这个问题的 4 个小时拿回来。

    【讨论】:

      【解决方案5】:

      我在 redmine repo 上进行了捆绑安装并得到了相同的错误消息:

      mysql.h 丢失。请检查您的mysql安装并重试。

      运行 Fedora 16 64 位,我所做的只是从发行版 rpm 安装 mysql-devel(开发包),问题就解决了!

      所以我觉得你可以

      yum install mysql-devel
      

      或 apt-get 缺少的开发包。

      【讨论】:

      • 这与 OS X 无关。
      • 嗯,它帮助了我......所以我很感激他/她发布了它!
      • 谢谢。有关信息,对于 Fedora 19 (mariadb),显然是 mariadb-devel
      • 感谢您的回答。它对我有帮助。
      【解决方案6】:

      这在我的 Mac OSX Lion 上对我有用:

      sudo env ARCHFLAGS="-I/usr/local/include/mysql/mysql  -pipe -fPIC    -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT  -DDONT_DECLARE_CXA_PURE_VIRTUAL" gem install mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/lib/mysql/mysql --with-mysql-include=/usr/local/include/mysql/mysql --with-mysql-config=/usr/local/bin/mysql_config
      

      This blog answered it.

      【讨论】:

        【解决方案7】:

        我尝试了此处发布的所有解决方案,但并不幸运。我用自制软件重新安装了 mysql 几次,但仍然没有运气。然后我发现了一篇包含解决方案的博客文章。

        我在/usr/local/Cellar/mysql/5.6.12/bin 中编辑了mysql_config 文件并删除了 W 编译器选项 -Wno-null-conversion-Wno-unused-private-field 用于 cflags 和 cxxflags。

        这解决了gem install mysql2bundle install 的问题

        参考:http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html

        【讨论】:

        • 已通过 OS X 10.8.3、XCode 4.6.3 和 MySQL 5.6.12 确认。
        • 遇到了同样的问题,这解决了我的问题。这些标志会不会被错误地引入?我过去使用酿造的 mysql 编译了 mysql2 gem,没有任何问题。
        • 在 10.8 / 5.6.12 上完美运行
        • 这没有任何意义!谢谢!
        • 谢谢!也拯救了我的一天。
        【解决方案8】:

        在我能发布的任何地方发布 - 希望它会帮助某人并节省他们很多时间。

        我在互联网和 Stack Overflow 上挖了 2 天,直到我找到 this link 然后开始通过 this ticket for mysql2 工作,我才真正解决了这个问题。

        使用我的设置(如票证中所述),-Wno-null-conversion -Wno-unused-private-field 的编译器开关会中断并给我一个不完全正确的错误,即:

        mysql.h is missing. please check your installation of mysql and try again
        

        【讨论】:

          【解决方案9】:

          对于不使用brew安装mysql并使用mysql 5.6及更高版本的人:

          根据this answer

          您需要编辑mysql_config,它放在我的案例中:/usr/local/mysql-5.6.12-osx10.7-x86_64/bin

          并将cflagscxxflags 更改为:

          cflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
          cxxflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
          

          经过此操作

          $ gem install mysql2 -v '0.3.13'
          

          完美无缺

          【讨论】:

          • 这在尝试安装 mysql2 0.3.11 的 OSX 10.9.4 上对我有用
          • 完美。使用 gem install mysql 在小牛队为我工作。非常感谢。
          【解决方案10】:

          我的问题是首先通过可下载的二进制文件安装 MySql 的结果。它最初安装在版本 5.5.28。然后我尝试通过自制软件安装。 Brew 安装了 5.6.x 版。但是在通过自制软件安装的过程中,/usr/local/mysql 的符号链接仍然指向 5.5.28。

          将您的符号链接更新为通过自制软件安装的任何版本。

          例如:/usr/local/mysql -> /usr/local/Cellar/mysql/5.6.13/

          这可能只是解决方案的一部分。

          【讨论】:

            【解决方案11】:

            对于那些在 Fedora 21 上的用户,并且您已经安装了 mysql-devel:

            yum install redhat-rpm-config
            

            为我解决了这个问题。看: redhat docs

            【讨论】:

              【解决方案12】:

              对于 mariadb:

              sudo apt-get install libmariadbclient18 libmariadbclient-dev
              

              然后

              gem install mysql2
              

              可以成功安装。

              【讨论】:

              • apt-get 在 Mac OS 上不可用。
              • 是的@ArtemZinnatullin——它适用于那些像我一样通过谷歌搜索“mysql.h is missing”来寻找解决方案的人。我浪费了一些时间来寻找解决方案并想帮助其他人。
              【解决方案13】:

              TL;DR:

              sudo ln -s /usr/local/opt/mysql@5.6 /usr/local/mysql
              

              我被这个问题困扰了将近 2 天,并多次重新安装 xcodemysql

              我最初使用brew 安装了mysql@5.6,但bundle install 命令一直失败,因为它找不到mysql 安装。以下错误输出:

              libmysqlclient is missing. You may need to 'brew install mysql' or 'port install mysql', and try again.
              

              但是,使用@Kevin Boedigheimer 的回答帮助解决了问题,即我将安装的mysql@5.6 链接到/usr/local/mysql

              sudo ln -s /usr/local/opt/mysql@5.6 /usr/local/mysql
              

              注意:如果您的 mysql 目录在其他地方,您可以使用以下命令找到它:

              find / -name 'mysql*5.6' 2&> /dev/null
              
              # '2&> /dev/null' ensures you have just the output you need
              

              【讨论】:

                猜你喜欢
                • 2012-06-22
                • 1970-01-01
                • 2012-09-11
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2012-02-20
                相关资源
                最近更新 更多