如何使用“mysql2” Windows 7 上 Rails 3 应用程序中的 gem?

发布于 2024-11-03 14:06:42 字数 986 浏览 10 评论 0原文

我尝试在 Windows 7 32 位上安装 mysql2 gem。

我运行:

gem install mysql2

并且收到以下错误:

ERROR:  Error installing mysql2:
        The 'mysql2' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

有什么想法可能导致此错误,以及如何解决此问题?


更新

我按照此处所述进行了所有操作,但我无法弄清楚最后一步:

gem install mysql2 -- 
     '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.1\lib\opt" 
      --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.1\include"'

我知道我应该将路径更改为系统中的正确路径,但我找不到 lib\opt 和我的 WAMP MySQL 安装中的 include 目录。我使用 WAMP 2.1。

请指教。

I try to install the mysql2 gem on Windows 7 32-bit.

I run:

gem install mysql2

and I get the following error:

ERROR:  Error installing mysql2:
        The 'mysql2' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

Any ideas what could cause this error, and how to solve this ?


UPDATE

I did everything as described here, but I can't figure out the last step:

gem install mysql2 -- 
     '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.1\lib\opt" 
      --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.1\include"'

I understand that I should change the paths to the correct paths in my system, but I can't find the lib\opt and the include directories in my WAMP MySQL installation. I use WAMP 2.1.

Please advise.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

甲如呢乙后呢 2024-11-10 14:06:42

对于任何感兴趣的人来说,这是一个正确的解决方案,它不会扰乱您当前安装的 mysql 服务器 -

编辑:确保您在 MySQL 服务器上下载正确的版本。 :

如果您打算连接到 6.0 或 5.5 服务器 - 下载这些二进制文件。我正在连接到 mysql 5.1 - 因此是我的例子。还要记住最新的 mysql2 gem(v 0.3.7)是针对 mysql 服务器 6 进行测试的 - 因此它始终无法在 Windows 上构建早期版本。还要确保在 ruby​​ 文件夹中使用正确的 libmysql.dll。

  1. 下载 mysql 服务器 5.1 的 zip 文件,而不是 msi 文件。确保它是 32 位而不是 64 位。 (从这里

  2. 由于没有安装程序文件,因此创建文件夹 c:\mysql-gem-install - 完成后可以将其删除。

  3. 将 zip 文件中的所有文件解压到您刚刚创建的文件夹中。

  4. 现在运行此命令

     gem install mysql2 -- '--with-mysql-lib="c:\mysql-gem-install\lib\opt" --with-mysql-include="c:\mysql-gem-安装\包含"'
    

我刚刚安装了 mysql2 gem v. 0.3.7

编辑 1
另一件事:确保直接在命令提示符中运行命令。与 PowerShell 或 Consol2 不同 - 出于某种原因,如果你尝试这样做,它会给你错误“无效选项” - 与解析方式有关。

编辑2
我刚刚进行了一个空白的 Windows 7 安装,我遇到的一件事是你需要再添加一个步骤:检查你的 ruby​​ bin 目录中是否有 libmysql.dll,如果没有从你的 mysql 复制一个安装。它应该与您的 mysql2 版本具有相同的版本。

Here is a proper solution for anyone interested, that doesn't mess up your current installation of mysql server -

EDIT : Make sure you download the right version on MySQL server. :

if you intend to connect to a 6.0 or 5.5 server - download those binaries. I'm connecting to mysql 5.1 - hence my example. Also keep in mind latest mysql2 gem ( v 0.3.7) was tested against mysql server 6 - hence it keeps failing to build on windows for earlier versions. also make sure you use the right libmysql.dll in your ruby folder.

  1. Download a zip file with mysql server 5.1 NOT the msi one. Make sure it's 32-bit NOT 64-bit. (From here)

  2. Since there is no installer file with this, create a folder c:\mysql-gem-install - you can remove it once you finish.

  3. Extract all the files from the zip file into the folder you just created.

  4. now run this command

     gem install mysql2 --  '--with-mysql-lib="c:\mysql-gem-install\lib\opt"  --with-mysql-include="c:\mysql-gem-install\include"'
    

I just installed mysql2 gem v. 0.3.7

EDIT 1
One more thing: make sure you run the command in Command Prompt directly. As in not PowerShell or Consol2 - for some reason if you try that it will give you and error " invalid option" - has to do with the way -- is parsed.

EDIT 2
I just was doing a blank windows 7 install and one thing I ran into is that you need to add one more step to this: check to see if there is libmysql.dll in your ruby bin directory, if not copy one over from your mysql install. It should be of the same version as your mysql2 build.

巨坚强 2024-11-10 14:06:42

谢谢你!需要注意的是:我还必须包含 --platform=ruby 选项。因此,最终的整个命令行是:

gem install mysql2 --platform=ruby -- '--with-mysql-lib="c:\mysql-gem-install\lib\opt" --with-mysql -include="c:\mysql-gem-install\include"'

当我在没有 platform=ruby 选项的情况下尝试时,DevKit 没有运行,它只是安装了普通的 mysql2 gem - 它甚至给出了警告关于为 6.0.2 构建 mysql2 的消息。我卸载了它(gem uninstall mysql2),然后使用 --platform=ruby 再次运行它,效果非常棒!

我:Windows 7 64位,Ruby 1.9.3p125,Rails 3.2.1,MySQL 5.1.56

THANK YOU! One note: I had to include the --platform=ruby option as well. Thus, the final entire command line was:

gem install mysql2 --platform=ruby -- '--with-mysql-lib="c:\mysql-gem-install\lib\opt" --with-mysql-include="c:\mysql-gem-install\include"'

When I tried it without the platform=ruby option, DevKit didn't run and it just installed the normal mysql2 gem - it even gave a warning message about mysql2 being built for 6.0.2. I uninstalled it (gem uninstall mysql2), then ran it again with --platform=ruby and it worked awesome!

Me: Windows 7 64bit, Ruby 1.9.3p125, Rails 3.2.1, MySQL 5.1.56

一个人练习一个人 2024-11-10 14:06:42

好吧,我并不真正使用 Windows,但是从“http://rubyinstaller.org/downloads”下载 DevKit 并按照“http://github.com/oneclick/rubyinstaller/wiki/Development-”中的说明进行操作怎么样?成套工具' ?

Well, i don't really use Windows, but what about downloading the DevKit from 'http://rubyinstaller.org/downloads' and following the instructions at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit' ?

孤星 2024-11-10 14:06:42

从 apachefriends.org 尝试 XAMPP,一定要下载完整版本,你会发现“lib”、“bin”、“include”和其他 MySQL 目录。有关更多详细信息,请参阅 -

http: //rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html

Try XAMPP from apachefriends.org, be sure to download the full version and you will find "lib", "bin", "include" and other MySQL directories. For further details, refer to -

http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html

青柠芒果 2024-11-10 14:06:42

您应该再次执行安装文件,并选择修改选项,然后检查开发组件。完成后,您将找到 include 文件夹和 opt 文件夹。

You should execute the setup file again,and choose the modify option,then check the Developer Components.When it finish,you will found the include folder and the opt folder.

暗地喜欢 2024-11-10 14:06:42

并非所有 mysql2 版本都附带 Windows 二进制文件。

在 Windows 上安装 gem mysql2 最简单的方法是选择包含 win 二进制文件的版本。

版本列表链接

选择包含“x86-mingw32”的最新版本号,

例如 0.3。 11

安装它:

gem install mysql2 -v 0.3.11

或在 gemfile 中:

gem „mysql2“, „0.3.11“

Not all mysql2 versions come with windows binaries.

Easiest way to install gem mysql2 on windows is to pick a version that includes win binaries.

Link to list of versions

Choose the latest version number that includes “x86-mingw32”

For example 0.3.11

To install it:

gem install mysql2 -v 0.3.11

or in the gemfile:

gem „mysql2“, „0.3.11“
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文