【问题标题】:How do I install the Rails MySQL adapter?如何安装 Rails MySQL 适配器?
【发布时间】:2011-01-04 18:32:54
【问题描述】:

我的问题仅此而已。 gem install mysql 不起作用,我在谷歌上没有找到任何东西。

当我尝试gem install mysql2 时,这就是我得到的。我现在不知道该怎么办。

jason@buster:~/projects/mcif-rails$ gem install mysql2
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

/home/jason/.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... yes
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=/home/jason/.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 /home/jason/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6 for inspection.
Results logged to /home/jason/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.6/ext/mysql2/gem_make.out

【问题讨论】:

  • 您运行的是什么操作系统?您似乎尚未安装 MySQL 和/或所需的开发库。
  • 我在 Linux 上。 MySQL 已安装,但几乎可以肯定没有安装开发库。我怎么知道那些是什么?
  • 这取决于您使用的是什么发行版(例如 Ubuntu、Red Hat、SUSE)?
  • 另外,mysql安装在哪里?如果它不在 /usr/local/mysql 下,您可能需要将一些选项传递给 gem 安装。
  • 没关系 - 其中一个答案给了我我需要的东西。不管怎么说,还是要谢谢你。 (如果你好奇的话,我在 Ubuntu 上。)

标签: mysql ruby-on-rails


【解决方案1】:

看起来您仍然需要安装 MySQL 的开发库。这些是在您的系统上成功构建 gem 所必需的。

[编辑] 似乎 RoR Wiki 不再可用。但是,Ubuntu 提供了their own walkthrough,这表明:

sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysql-ruby libmysqlclient-dev
sudo gem install mysql

详情请见http://wiki.rubyonrails.org/database-support/mysql#installation。

示例:Ubuntu

sudo apt-get install mysql-server mysql-server-5.0 libmysqlclient15off \
    libmysqlclient15-dev mysql-client-5.0 mysql-common

sudo apt-get install libmysql++-dev

sudo gem install mysql

【讨论】:

  • 在 Ubuntu 14.04 libmysql-ruby 上不需要
  • 在 Ubuntu 14.04 上也没有“mysql”包
【解决方案2】:

我将把它留在这里:

我遇到了类似的问题,然后意识到如果没有在我的开发机器上安装 MySQL 就无法安装 mysql2 gem(即使我只使用 mysql2 gem 连接到远程 MySQL 服务器)。

::额头一巴掌::

brew install mysql

然后,在我的 Gemfile 中:

gem 'mysql2', '~> 0.3.11'

紧随其后

bundle install

成功了!

【讨论】:

    【解决方案3】:

    如果你运行的是 Rails 3,你应该使用 mysql2 gem。你可以安装它:

    gem install mysql2
    

    您需要先安装 MySQL 和所有开发头文件。这将因不同的操作系统而异。在 Ubuntu 上,您可以运行:

    aptitude install mysql-server 
    aptitude install mysql-client
    aptitude install mysql-common
    aptitude install libmysql-ruby
    aptitude install libmysqlclient-dev
    

    如果您正在创建一个新项目,请使用:

    rails new sample --database=mysql
    cd sample
    bundle install
    

    更多详情,请查看project repository。

    【讨论】:

      【解决方案4】:

      我假设您正在使用 Rails。

      在您的 Gemfile 中:

      gem 'mysql2'
      

      然后在你的终端中:

      bundle
      

      【讨论】:

      • 当它到达mysql2 时,它就像我尝试gem install mysql2 时一样。我已经编辑了我的问题以显示会发生什么。
      【解决方案5】:

      2013 年,使用 Ubuntu 12.04,这对我有用:

      sudo apt-get install mysql-client libmysqlclient-dev
      
      bundle install
      

      【讨论】:

        猜你喜欢
        • 2012-03-25
        • 1970-01-01
        • 1970-01-01
        • 2013-05-09
        • 2013-01-16
        • 1970-01-01
        • 1970-01-01
        • 2012-04-04
        • 2011-09-22
        相关资源
        最近更新 更多