【问题标题】:How to connect Ruby on rails with MySQL如何将 Ruby on rails 与 MySQL 连接起来
【发布时间】:2016-05-03 04:25:37
【问题描述】:

我最近安装了 Ruby on rails 和 MySQL。 版本是 ruby​​ 2.1.7 和 MySQL Workbench 6.3 CE。 我输入了gem install mysql2 -v=0.2.6,这发生了;

Fetching: mysql2-0.2.6.gem <100%>
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
       Error: Failed to build gem native extensions.

    C:/Ruby21/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checkimg for main() in -llibmysql... 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 option:
    --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=.
    --curdit
    --ruby=C:Ruby21/bin/ruby
    --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-libmysqllib
    --without-libmysqllib

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby21/lib/ruby/gems/2.1.0/gems/mysql2-0.2
.6 for inspection.
Results logged to C:/Ruby21/lib/ruby/gems/2.1.0/extensions/x86-mingw32/2.1.0/mys
ql2-0.2.6/gem_make.out

谁能帮我把 Ruby on rails 和 MySQL 连接起来?

【问题讨论】:

标签: mysql ruby-on-rails ruby windows


【解决方案1】:

来自https://github.com/brianmario/mysql2

Linux 和其他 Unix

您可能需要安装 libmysqlclient-dev 或 mysql-devel 等软件包;请参阅您的发行版的包指南以找到特定的包。我们看到的最常见问题是拥有库文件 libmysqlclient.so 但缺少头文件 mysql.h 的用户——仔细检查您是否安装了 -dev 包。

正确的解决方案取决于您的操作系统。由于 mysql2 代码部分是用 C 编写的,因此您需要在系统上安装一些库文件来安装它。

【讨论】:

  • 当我输入 ruby -v 时,结果是 ruby 2.1.7p400 &lt;2015-08-18 revision 51632&gt; [i386-mingw32] .. 当 gem -v 时,结果是 2.2.5,这意味着安装了开发包对吗?
  • 它只是意味着安装了ruby,但是你需要libmysqlclient.so,它没有随ruby一起提供。您可以通过包管理器获取它(例如,基于 debian 的发行版中的apt-get)。
猜你喜欢
  • 1970-01-01
  • 2015-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-08
相关资源
最近更新 更多