在 Windows 7 上安装 Ruby MYSQL2 gem [英] Ruby MYSQL2 gem installation on windows 7

查看:39
本文介绍了在 Windows 7 上安装 Ruby MYSQL2 gem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows 7 上安装 mysql2 gem 我从 mysql 站点下载了连接器并将 libmysql.dll 放在 ruby​​200in

I'm trying to installing the mysql2 gem on windows 7 I downloaded the connector from the mysql site and placed the libmysql.dll in ruby200in

然后做 gem install mysql2

then do gem install mysql2

这些是我在这里昏暗的结果吗?

These are the results am I being dim here?

Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    C:/Ruby200/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
*** 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=C:/Ruby200/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}/
extconf.rb:37:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError
)


Gem files will remain installed in C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.
3.13 for inspection.
Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/ext/mysql2/g
em_make.out

推荐答案

EDIT 30/09/2014

发布此答案时,64 位 Rails 安装程序不是推荐的版本 - 现在似乎人们开始更多地使用它.需要注意的是,当您下载 MySQL Connector 时,您需要下载 64 位或 32 位以与您安装的 rails 版本相对应.

When this answer was posted the 64 bit rails installer wasn't the recommended version - it now seems people are starting to use it more. It should be noted when you download the MySQL Connector you need to download either 64 or 32bit to correspond to the version of rails you installed.

令人惊讶的是,今天早上我很幸运地得到了答案,因为我碰巧正在寻找其他类似性质的东西.我不太确定为什么没有一个简单的指南,因为它看起来非常简单!

Amazingly I lucked upon an answer very early this morning as I happened to be looking for something else of a similar nature. I'm not quite sure why there isn't a single simple guide for this as it appears to be very straight forward!

出于某种原因,在安装 gem 时仅指定 mysql-dir 并不能使用其他子目录,因此您需要手动设置参数.

For some reason just specifying the mysql-dir when you install the gem doesn't pick up with other sub directories so you need to set the parameters manually.

对于遇到同样问题的其他人,我做了以下事情:

For anyone else experiencing the same problem, I did the following:

1) 从以下位置下载 MySql C 连接器:http://dev.mysql.com/downloads/connector/c/

1) Download the MySql C Connector from: http://dev.mysql.com/downloads/connector/c/

注意不要下载安装程序,为您的操作系统下载存档

下载与您安装的 rails 版本相对应的 32 位或 64 位 ARCHIVE.

2) 将文件解压到 C:mysql-connector

2) Extract the file to C:mysql-connector

3) 然后运行:

 gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:mysql-connectorlib" --with-mysql-include="C:mysql-connectorinclude" --with-mysql-dir="C:mysql-connector"'

瞧,一切正常.

编辑 30/01/2014

我只需要在砖砌的机器上进行全新安装,第 3 步中的命令不起作用,起作用的是:

I just had to do a fresh install on a bricked machine and the command in step 3 didn't work, what did work was:

gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:mysql-connector"'

我不太确定有什么区别,但这次它似乎可以正常拾取目录,所以如果第一个不起作用,试试这个!

I'm not quite sure what the difference is but this time it seems to be picking up the directories ok, so if the first one doesn't work try this one!

我认为这与您如何安装导轨有关,这一次我使用了 railsinstaller,它似乎可以正确设置路径.

I think this has to do with how you go about installing rails, this time round I used the railsinstaller which seems to set the paths up correctly.

这里的很多结果似乎取决于您使用的 shell,很多人在使用 powershell 时遇到问题,所以我不建议使用它.我是在提升的命令提示符下执行此操作的.

A lot of the outcome here seems to depend on the shell your using, a lot of people are having problems with powershell so I wouldn't advise using it. I did this in an elevated command prompt.

哦,最后,如果您在执行 RAILS S 时遇到有关 mysql2 gem 的错误,您需要将 libmysql.dll 从 mysql 连接器的 LIB 目录复制到安装了 rails 的 bin 目录中.

Oh and lastly if you get an error regarding the mysql2 gem when you do RAILS S you need to copy the libmysql.dll from the LIB directory of the mysql connector to the bin directory where rails has been installed.

这篇关于在 Windows 7 上安装 Ruby MYSQL2 gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆