在 Windows 7 上安装 Ruby MYSQL2 gem
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19014117/
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
Ruby MYSQL2 gem installation on windows 7
提问by Mrk Fldig
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 ruby200\bin
我正在尝试在 Windows 7 上安装 mysql2 gem 我从 mysql 站点下载了连接器并将 libmysql.dll 放在 ruby200\bin
then do gem install mysql2
然后做 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
回答by Mrk Fldig
EDIT 30/09/2014
编辑 30/09/2014
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.
当发布此答案时,64 位 Rails 安装程序不是推荐的版本 - 现在似乎人们开始更多地使用它。需要注意的是,当您下载 MySQL Connector 时,您需要下载 64 位或 32 位以与您安装的 rails 版本相对应。
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!
令人惊讶的是,今天早上我很幸运地得到了答案,因为我碰巧正在寻找其他类似性质的东西。我不太确定为什么没有一个简单的指南,因为它看起来非常简单!
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.
出于某种原因,在安装 gem 时仅指定 mysql-dir 不会与其他子目录一起使用,因此您需要手动设置参数。
For anyone else experiencing the same problem, I did the following:
对于遇到同样问题的其他人,我做了以下事情:
1) Download the MySql C Connector from: http://dev.mysql.com/downloads/connector/c/
1) 从以下位置下载 MySql C 连接器:http: //dev.mysql.com/downloads/connector/c/
NOTE Don't download the installer, download the ARCHIVE for your OS
注意不要下载安装程序,为您的操作系统下载 ARCHIVE
Download either the 32bit or 64 bit ARCHIVE to correspond with the version of rails you installed.
下载 32 位或 64 位 ARCHIVE 以与您安装的 rails 版本相对应。
2) Extract the file to C:\mysql-connector
2) 将文件解压到 C:\mysql-connector
3) Then ran:
3)然后运行:
gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\mysql-connector\lib" --with-mysql-include="C:\mysql-connector\include" --with-mysql-dir="C:\mysql-connector"'
Voila everything is working fine.
瞧,一切正常。
EDIT 30/01/2014
编辑 30/01/2014
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:
我只需要在砖砌的机器上进行全新安装,第 3 步中的命令不起作用,起作用的是:
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!
我不太确定有什么区别,但这次它似乎正在拾取目录,所以如果第一个不起作用,请尝试这个!
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.
我认为这与您如何安装导轨有关,这一次我使用了 railsinstaller,它似乎可以正确设置路径。
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.
这里的很多结果似乎取决于您使用的 shell,很多人在使用 powershell 时遇到问题,所以我不建议使用它。我在提升的命令提示符下执行此操作。
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.
哦,最后,如果您在执行 RAILS S 时遇到有关 mysql2 gem 的错误,您需要将 libmysql.dll 从 mysql 连接器的 LIB 目录复制到安装了 rails 的 bin 目录。
回答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 Nebojisa
Steps for Ruby 2.1.3, Windows 8.1 and MySQL Server 5.7. All x64 bit.
Ruby 2.1.3、Windows 8.1 和 MySQL Server 5.7 的步骤。所有 x64 位。
- Download Development Kit
- Extracted Development Kit.
- Run CMD and go to dir where is Development Kit extracted
- Run
ruby dk.rb init - Run
ruby dk.rb install - Run
gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.7\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.7\include" --with-mysql-dir="c:\Program Files\MySQL\MySQL Server 5.7"'
- 下载 开发套件
- 提取的开发工具包。
- 运行 CMD 并转到提取开发工具包的目录
- 跑
ruby dk.rb init - 跑
ruby dk.rb install - 跑
gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.7\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.7\include" --with-mysql-dir="c:\Program Files\MySQL\MySQL Server 5.7"'
回答by Omar M.
This is what worked for me for the same error on Windows 8 64-bit and using ruby 64-bit
这对我在 Windows 8 64 位和使用 ruby 64 位上的相同错误有用
- Download and install MySQL Server 5.6 64-bit
Run this command:
gem install mysql2 -v '0.3.16' -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.6\include"'
- 下载并安装 MySQL Server 5.6 64 位
运行此命令:
gem install mysql2 -v '0.3.16' -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.6\include"'
Hope this helps
希望这可以帮助
回答by Gediminas
I have tried all provided methods but the same error appears again and again :(
我已经尝试了所有提供的方法,但一次又一次出现相同的错误:(
Fortunately, older version installed without any errors!
幸运的是,旧版本安装没有任何错误!
gem uninstall mysql2
gem install mysql2 -v 0.2.6
回答by user1105056
Here's what worked for me:
以下是对我有用的内容:
gem install mysql2 -- '--with-mysql-dir="C:\wamp\bin\mysql\mysql5.5.xx"'
Been searching for a few hours and not seen this variation suggested, so hopefully it will help someone!
已经搜索了几个小时,但没有看到建议的这种变化,所以希望它会对某人有所帮助!
回答by hira umair
Also try disabling your antivirus before installing the gem. Mine got installed after I ran following command :
在安装 gem 之前,请尝试禁用防病毒软件。我在运行以下命令后安装了:
gem install mysql2 --platform=ruby -- '--with-mysql-lib=
"C:\mysql-connector\lib" --with-mysql-include="C:\mysql-connector\include" --wit
h-mysql-dir="C:\mysql-connector"'
Same command was not working when my antivirus was enabled, as it was pushing some ruby file to chest. Hope this helps someone.
当我的防病毒软件启用时,相同的命令不起作用,因为它正在将一些 ruby 文件推送到胸部。希望这可以帮助某人。
回答by Edoardo
Try to follow those steps:
尝试按照以下步骤操作:
I assume:
我假设:
- a) you use windows7
- b) ruby 2+ on C:\Ruby200-x64
- c) rails 4+ installed on ruby
- d) WAMP installed on C:\wamp and running
- a) 你使用 windows7
- b) C:\Ruby200-x64 上的 ruby 2+
- c) 安装在 ruby 上的 rails 4+
- d) WAMP 安装在 C:\wamp 并运行
1) uninstall your myslq2 gem:
1) 卸载你的 myslq2 gem:
$ gem uninstall mysql2
2) reinstall the mysql2 gem with path option:
2)使用路径选项重新安装mysql2 gem:
$ gem install mysql2 -- '--with-mysql-lib="C:\wamp\bin\mysql\mysql5.6.12\lib" --with-mysql-include="C:\wamp\bin\mysql\mysql5.6.12\include"'
3) copy the libmysql.dll you find in C:\wamp\bin\mysql\mysql5.6.12\lib into C:\Ruby200-x64\bin
3)将你在C:\wamp\bin\mysql\mysql5.6.12\lib中找到的libmysql.dll复制到C:\Ruby200-x64\bin
4) open in your rails app the file "Gemfile" and edit it enabling the mysql2, by adding:
4) 在您的 Rails 应用程序中打开文件“Gemfile”并编辑它以启用 mysql2,添加:
gem 'mysql2'
5) start your rails server:
5)启动你的rails服务器:
$ rails server
6) open your browser and go to localhost:3000/
6) 打开浏览器并转到 localhost:3000/
回答by Prasanth RJ
I am still having problem with mysql2 gem but below approach helped me install mysql with RoR on Windows Env.
我仍然遇到 mysql2 gem 问题,但下面的方法帮助我在 Windows Env 上安装了带有 RoR 的 mysql。
Step 1 : Gem File changes : ({app}/Gemfile)
第 1 步:Gem 文件更改:({app}/Gemfile)
Update mysql2 --> mysql
更新 mysql2 --> mysql
Step 2 : Updates in database.yml file ({app}/config/database.yml)
第 2 步:更新 database.yml 文件 ({app}/config/database.yml)
Change adapter: mysql2 --> adapter: mysql
更改适配器:mysql2 --> 适配器:mysql
host: localhost --> host: 127.0.0.1
主机:本地主机 --> 主机:127.0.0.1
Step 3 : Downoad mysql-connector-c-noinstall-6.0.2-win32
第 3 步:下载 mysql-connector-c-noinstall-6.0.2-win32
Step 4 : Copy mysql-connector-c-noinstall-6.0.2-win32\lib\libmysql.dll file to C:\RailsInstaller\Ruby1.9.3\bin
第 4 步:将 mysql-connector-c-noinstall-6.0.2-win32\lib\libmysql.dll 文件复制到 C:\RailsInstaller\Ruby1.9.3\bin
Step 5 :bundle update && Start rails server
第 5 步:捆绑更新 && 启动 rails 服务器
回答by ndas
For Cygwin, I could consolidate various steps.
对于 Cygwin,我可以整合各个步骤。
- Use cygwin setup.exe to download gcc, g++, make, cmake and libmysqlclient-devel (from cygwin ports)
- Download c/connector src for windows from mysql site. I downloaded 6.x version. OR download libmysqlclient-devel's version (not sure from where)
- unzip
- cd dir_connector
- Not required and RISKY, but if cygwin libmysqlclient-devel version is 5.5.40 , then change dir_connector/VERSION file's versions to 5.5.40
- mkdir build
- cd build
- comment dtoa in stdlib.h, else compilation is failing
- cmake ..
- make
- make install
- gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
- 使用 cygwin setup.exe 下载 gcc、g++、make、cmake 和 libmysqlclient-devel(从 cygwin 端口)
- 从 mysql 站点下载 c/connector src for windows。我下载了 6.x 版本。或者下载 libmysqlclient-devel 的版本(不知道从哪里来)
- 解压
- cd dir_connector
- 不需要且有风险,但如果 cygwin libmysqlclient-devel 版本为 5.5.40 ,则将 dir_connector/VERSION 文件的版本更改为 5.5.40
- mkdir 构建
- 光盘构建
- 在 stdlib.h 中注释 dtoa,否则编译失败
- cmake ..
- 制作
- 进行安装
- gem install mysql2 --with-mysql-config=/usr/local/mysql/bin/mysql_config

