Ruby-on-rails 无法在 Windows 7 上安装 MySQL2 gem
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5367563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to install MySQL2 gem on Windows 7
提问by Lohith MV
I am getting the following error message while installing, let me know if I need to post more details.
我在安装时收到以下错误消息,如果我需要发布更多详细信息,请告诉我。
I followed instructions from the following location: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
我按照以下位置的说明进行操作:https: //github.com/oneclick/rubyinstaller/wiki/Development-Kit
I am using ruby 1.9.2p136 (2010-12-25) [i386-mingw32].
我正在使用 ruby 1.9.2p136 (2010-12-25) [i386-mingw32]。
Here is what I get:
这是我得到的:
E:\work_desk\trunk>gem install mysql2 -v 0.2.4
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:/Ruby192/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checking 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 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:/Ruby192/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
Gem files will remain installed in C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.
2.4 for inspection.
Results logged to C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.4/ext/mysql2/ge
m_make.out
回答by Luis Lavena
The specific version of mysql2 gem you're trying to install (0.2.4) not only lacks binaries for Windows, but have issues on Windows.
您尝试安装的特定版本的 mysql2 gem (0.2.4) 不仅缺少适用于 Windows 的二进制文件,而且在 Windows 上也存在问题。
Please install mysql2 gem without indicating the version:
请安装 mysql2 gem 而不标明版本:
gem install mysql2
Which will install latest version (0.2.6 at the time of my posting this) and also provides binaries for Windows which skip the compilation step.
它将安装最新版本(在我发布这篇文章时为 0.2.6),并且还提供跳过编译步骤的 Windows 二进制文件。
Ifyou still want to force the compilation (because your version of MySQL differs from the one used to generate the binary gem, you will need to install RubyInstaller's DevKit from RubyInstaller website:
如果您仍想强制编译(因为您的 MySQL 版本与用于生成二进制 gem 的版本不同,您需要从 RubyInstaller 网站安装 RubyInstaller 的 DevKit:
http://rubyinstaller.org/downloads
http://rubyinstaller.org/downloads
And follow the DevKit installation instructionsfrom our wiki (that is linked from the download page)
并遵循我们 wiki 中的DevKit 安装说明(从下载页面链接)
You will need to provide the path to both headers and libraries during the gem installation process, and adjust the MySQL installation location from the following instructions:
您需要在 gem 安装过程中提供头文件和库的路径,并根据以下说明调整 MySQL 安装位置:
subst X: "C:\Program Files (x86)\MySQL\MySQL Server 5.1"
gem install mysql2 --platform=ruby -- --with-mysql-dir=X: --with-mysql-lib=X:\lib\opt
subst X: /D
The above command uses substto avoid issues with path with spaces, which you should avoid always.
上面的命令用于subst避免带有空格的路径问题,您应该始终避免使用空格。
Hope this helps.
希望这可以帮助。
回答by Sawant
After searching around for a way to make it work, I finally got it installed with the following on the command prompt:
在四处寻找使其工作的方法后,我终于在命令提示符下使用以下内容安装了它:
gem install mysql2 -v 0.2.6
With the following results:
结果如下:
Fetching: mysql2-0.2.6-x86-mingw32.gem (100%)
Successfully installed mysql2-0.2.6-x86-minw32
1 gem installed
Installing ri documentation for mysql2-0.2.6-x86-mingw32...
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6-x86-mingw32...
Enclosing class/module 'mMysql2' for class Client not known
Try it. It should work.
尝试一下。它应该工作。
回答by Ritesh Kumar
If still not able to install mysql2 gem on windows7 or not very clear on the steps to follow, then please go through this post which will help you in step-by-step installation - http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
如果仍然无法在 windows7 上安装 mysql2 gem 或者对要遵循的步骤不是很清楚,那么请阅读这篇文章,它将帮助您逐步安装 - http://rorguide.blogspot.com/2011/ 03/installing-mysql2-gem-on-ruby-192-and.html
And for mysql_api.so error (C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/1.9/mysql_api.so), copy "libmySQL.dll" file from C:\Program Files\MySQL\MySQL Server 5.1\binto C:\Ruby192\bin
对于 mysql_api.so 错误(C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql-2.8.1-x86-mingw32/lib/1.9/mysql_api.so),将“libmySQL.dll”文件复制C:\Program Files\MySQL\MySQL Server 5.1\bin到C:\Ruby192\bin
Path of installation may vary, for details refer to this post - http://rorguide.blogspot.com/2011/03/getting-error-specified-module-could.html.
安装路径可能会有所不同,有关详细信息,请参阅此帖子 - http://rorguide.blogspot.com/2011/03/getting-error-specified-module-could.html。
Hope, this will help you in sorting out your issues.
希望这能帮助您解决问题。
回答by Duke
Start with RailsInstaller.
从 RailsInstaller 开始。
This is assuming you are running the mysql server locally (local development), and your Ruby is compiled 32-bit. (Check ruby -v. x64 || i386.)
这是假设您在本地运行 mysql 服务器(本地开发),并且您的 Ruby 编译为 32 位。(检查ruby -v.x64 || i386。)
Download the mysql-community-web-installer. In the top right select 32-bit. You pretty much just need the Server. The Workbench is handy also.
下载 mysql-community-web-installer。在右上角选择 32-bit。您几乎只需要服务器。工作台也很方便。
The gem command needs a path without spaces, so use subst:
gem 命令需要一个没有空格的路径,所以使用 subst:
subst X: "C:\Program Files (x86)\MySQL\MySQL Server 5.6"
gem install mysql2 -v=0.3.13 --platform=ruby -- --with-mysql-dir=X:
You will need libmysql.dll in the PATH -- the easiest thing is just to copy it to Ruby's bin directory:
您将需要 PATH 中的 libmysql.dll —— 最简单的方法就是将其复制到 Ruby 的 bin 目录:
copy "C:\Program Files (x86)\MySQL\MySQL Server 5.6\lib\libmysql.dll" "C:\RailsInstaller\Ruby2.0.0\bin"
NOTES
笔记
Don't do this from PowerShell! (DevKit has trouble changing path info in powershell.)
不要从 PowerShell 执行此操作!(DevKit 无法在 powershell 中更改路径信息。)
Make sure all libraries are 32-bit, since RailsInstaller's ruby etc. are all compiled 32-bit and need to link to 32-bit libraries.
确保所有库都是 32 位的,因为 RailsInstaller 的 ruby 等都是 32 位编译的,需要链接到 32 位库。
If you don't want a server locally, just install the C Connector, and do these instructions with that directory and libmysql.dll. Don't mix and match -- make sure the .dll matches the version you compiled the gem against.
如果您不需要本地服务器,只需安装 C 连接器,并使用该目录和 libmysql.dll 执行这些说明。不要混合和匹配——确保 .dll 与您编译 gem 的版本匹配。
回答by Yakob Ubaidi
回答by André Herculano
I've tried the solution of @Mrk Fldig but it didn't work... So what solved the problem was:
我已经尝试过@Mrk Fldig 的解决方案,但没有奏效......所以解决问题的是:
- Downloaded the lastest MySQL Installerfor windows 7 32 bits
- Installed the gem with the following command:
gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/Program Files/MySQL/MySQL Connector C 6.1 6.1.2/"'
- 下载适用于 Windows 7 32 位的最新 MySQL安装程序
- 使用以下命令安装 gem:
gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/Program Files/MySQL/MySQL Connector C 6.1 6.1.2/"'
One pitfall to be aware of is that I changed the backslashes (\) to normal slashes (/). I've tried the same procedure with backslashes and it didn't work.
要注意的一个陷阱是我将反斜杠 (\) 更改为普通斜杠 (/)。我已经用反斜杠尝试了相同的过程,但没有奏效。
The installer already includes the C connectors for MySQL at MySQL Connector C 6.1 6.1.2directory. Therefore, passing only the --with-mysql-dirparameter without the --with-mysql-libor --with-mysql-includeparameters, makes the gem to look at the same directory for the liband includedirectories
安装程序已在MySQL Connector C 6.1 6.1.2目录中包含 MySQL 的 C 连接器。因此,只传递--with-mysql-dir没有--with-mysql-libor--with-mysql-include参数的参数,会使 gem 在同一个目录中查找libandinclude目录
回答by the Tin Man
From this:
由此:
checking for main() in -llibmysql... no
it looks like you haven't installed the MySQL drivers and apps. If so, were they allowed to install into their default locations? At a minimum you'll want the client software if the server is running on a different machine.
看起来您还没有安装 MySQL 驱动程序和应用程序。如果是这样,他们是否被允许安装到默认位置?如果服务器在不同的机器上运行,您至少需要客户端软件。

