MySQL 无法安装 mysql2 gem
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5841406/
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
Cannot install mysql2 gem
提问by codingbunny
I'm unable to install the mysql2 gem in my Windows7 x64 system. I tried using both the 32-bit and 64-bit versions of MySQL server but none got me any further.
我无法在我的 Windows7 x64 系统中安装 mysql2 gem。我尝试使用 32 位和 64 位版本的 MySQL 服务器,但都没有让我更进一步。
I installed Ruby 1.8, the development kit and and the Rails platform. I even installed minGW to allow C++/C compilation of things. MySQL Server was installed in the default location.
我安装了 Ruby 1.8、开发工具包和 Rails 平台。我什至安装了 minGW 来允许 C++/C 编译东西。MySQL 服务器安装在默认位置。
When running the command:
运行命令时:
C:\Users\Arne>gem install mysql2 -- --with-mysql-include="C:\Program Files (x86)\MySQL\MySQL Server 5.1\include" --with-mysql-lib="C:\Program Files (x86)\MySQL\MySQL Server 5.1\lib\"
I receive the following output from the console:
我从控制台收到以下输出:
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
*** 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:/Ruby/bin/ruby
--with-mysql-dir
--without-mysql-dir
--with-mysql-include=${mysql-dir}/include
--with-mysql-lib=${mysql-dir}/lib
--with-libmysqllib
--without-libmysqllib
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
C:/Ruby/bin/ruby.exe extconf.rb --with-mysql-include=C:\Program Files (x
86)\MySQL\MySQL Server 5.1\include --with-mysql-lib=C:\Program Files (x86)\MySQL
\MySQL Server 5.1\lib"
checking for rb_thread_blocking_region()... no
checking for main() in -llibmysql... no
Gem files will remain installed in C:/Ruby/lib/ruby/gems/1.8/gems/mysql2-0.3.2 f
or inspection.
Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/mysql2-0.3.2/ext/mysql2/gem_mak
e.out
The output of my environment according to Rubygems is:
根据 Rubygems,我的环境的输出是:
C:\Users\Arne>gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.7.2
- RUBY VERSION: 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
- INSTALLATION DIRECTORY: C:/Ruby/lib/ruby/gems/1.8
- RUBY EXECUTABLE: C:/Ruby/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/Ruby/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- C:/Ruby/lib/ruby/gems/1.8
- C:/Users/Arne/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
The following gems have been installed on the system as well:
系统上还安装了以下 gem:
C:\Users\Arne>gem list --local
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.7)
actionpack (3.0.7)
activemodel (3.0.7)
activerecord (3.0.7)
activeresource (3.0.7)
activesupport (3.0.7)
arel (2.0.9)
builder (3.0.0, 2.1.2)
bundler (1.0.12)
erubis (2.7.0, 2.6.6)
fastthread (1.0.7)
i18n (0.5.0)
mail (2.3.0, 2.2.18)
mime-types (1.16)
mysql (2.8.1 x86-mingw32)
polyglot (0.3.1)
rack (1.2.2)
rack-mount (0.7.2, 0.6.14)
rack-test (0.5.7)
rails (3.0.7)
railties (3.0.7)
rake (0.8.7)
rdoc (3.5.3, 2.5.11)
rdoc-data (2.5.3)
rubygems-update (1.7.2)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.27, 0.3.26)
I don't know what's missing or wrong, but the output files pointed to by the script contain the following data:
我不知道缺少什么或错误,但脚本指向的输出文件包含以下数据:
mkmf.log:
mkmf.log:
have_func: checking for rb_thread_blocking_region()... -------------------- no
"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -g -O2 -DFD_SETSIZE=256 conftest.c -L. -LC:/Ruby/lib -L. -lmsvcrt-ruby18-static -lshell32 -lws2_32 "
conftest.c: In function 't':
conftest.c:7:53: error: 'rb_thread_blocking_region' undeclared (first use in this function)
conftest.c:7:53: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin */
1: #include <ws2tcpip.h>
2: #include <winsock2.h>
3: #include <windows.h>
4:
5: /*top*/
6: int main() { return 0; }
7: int t() { void ((*volatile p)()); p = (void ((*)()))rb_thread_blocking_region; return 0; }
/* end */
"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -g -O2 -DFD_SETSIZE=256 conftest.c -L. -LC:/Ruby/lib -L. -lmsvcrt-ruby18-static -lshell32 -lws2_32 "
C:\Users\Arne\AppData\Local\Temp\ccCicaNu.o: In function `t':
C:\Ruby\lib\ruby\gems.8\gems\mysql2-0.3.2\ext\mysql2/conftest.c:3: undefined reference to `rb_thread_blocking_region'
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { rb_thread_blocking_region(); return 0; }
/* end */
--------------------
have_library: checking for main() in -llibmysql... -------------------- no
"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -IC:\Program -g -O2 -DFD_SETSIZE=256 conftest.c -L. -LC:/Ruby/lib -LC:\Program -L. -lmsvcrt-ruby18-static -llibmysql -lshell32 -lws2_32 "
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -llibmysql
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include <ws2tcpip.h>
2: #include <winsock2.h>
3: #include <windows.h>
4:
5: /*top*/
6: int main() { return 0; }
7: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
/* end */
"gcc -o conftest -I. -IC:/Ruby/lib/ruby/1.8/i386-mingw32 -I. -IC:\Program -g -O2 -DFD_SETSIZE=256 conftest.c -L. -LC:/Ruby/lib -LC:\Program -L. -lmsvcrt-ruby18-static -llibmysql -lshell32 -lws2_32 "
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -llibmysql
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { main(); return 0; }
/* end */
--------------------
gem_make.out:
gem_make.out:
C:/Ruby/bin/ruby.exe extconf.rb --with-mysql-include=C:\Program Files (x86)\MySQL\MySQL Server 5.1\include --with-mysql-lib=C:\Program Files (x86)\MySQL\MySQL Server 5.1\lib"
checking for rb_thread_blocking_region()... no
checking for main() in -llibmysql... no
I hope someone can point what I'm doing wrong, or what is actually missing on my development system to get this gem properly installed and working.
我希望有人能指出我做错了什么,或者我的开发系统中实际上缺少什么以使这个 gem 正确安装和工作。
回答by codingbunny
I finally solved it:
我终于解决了:
- Downloaded and installed MySQL 64bit version 5.5
- Downloaded the zip archive for the 32bit version 5.5.
- Extracted the 32-bit include and lib folders to
C:\MySQL
. - Installed Ruby 1.9.2.
- Installed the Ruby Devkit.
- Installed the gems:
gem install mysql
gem install mysql2 -- --with-mysql-lib=C:\MySQL\lib --with-mysql-include=C:\MySQL\include
gem install rails
gem install fastthread
gem install haml
- 下载并安装 MySQL 64bit version 5.5
- 下载了 32 位版本 5.5 的 zip 存档。
- 将 32 位 include 和 lib 文件夹解压缩到
C:\MySQL
. - 安装了 Ruby 1.9.2。
- 安装了 Ruby Devkit。
- 安装宝石:
gem install mysql
gem install mysql2 -- --with-mysql-lib=C:\MySQL\lib --with-mysql-include=C:\MySQL\include
gem install rails
gem install fastthread
gem install haml
It's working as a charm now. It seems the MySQL gem has issues finding the data when dealing with 64-bit.
它现在正在发挥作用。在处理 64 位时,MySQL gem 似乎在查找数据时遇到问题。
回答by JohnF
Here's what worked for me using: Win7 64/MySQL 5.5 64-bit/Ruby 1.9.2:
以下是对我有用的:Win7 64/MySQL 5.5 64-bit/Ruby 1.9.2:
- Download libmysql.dll.
- Copy the above libmysql.dll to
C:\Ruby192\bin
ANDC:\Ruby192\lib
, or wherever your lib and bin are. - Run:
- 下载libmysql.dll。
- 将上面的 libmysql.dll 复制到
C:\Ruby192\bin
ANDC:\Ruby192\lib
,或者你的 lib 和 bin 所在的任何地方。 - 跑:
gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include" --with-mysql-dir="c:\Program Files\MySQL\MySQL Server 5.5"'
Good luck.
祝你好运。
回答by Ritesh Kumar
If still getting error then cross check the steps of installation on -
如果仍然出现错误,请交叉检查安装步骤 -
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html
where most of the user were able to install mysql2 gem after following the described steps.
在按照描述的步骤之后,大多数用户都能够安装 mysql2 gem。
回答by MM.
The accepted answer did not work for me, and neither did the the other 2. However, a comment by MG on the link from Ritesh did the trick for me. I had to specify version 0.2.6, and include the parameter --platform=ruby. (Note: I also had to download the "noinstall" version of MySQL to get the /lib/opt)
接受的答案对我不起作用,其他两个也不起作用。但是,MG 对 Ritesh 链接的评论对我有用。我必须指定版本 0.2.6,并包含参数 --platform=ruby。(注意:我还必须下载 MySQL 的“noinstall”版本才能获得 /lib/opt)
Here is how I got the gem installed on Windows
这是我在 Windows 上安装 gem 的方法
gem install mysql2 -v 0.2.6 -- --platform=ruby --with-mysql-lib=C:\Ruby192\MySQL\lib\opt --with-mysql-dir=C:\Ruby192\MySQL
回答by PedroSena
I know the thread is related to Windows but I reached it searching for the same issue on Linux and I fixed it by installing the lib "libmysqlclient-dev"
我知道该线程与 Windows 相关,但我在 Linux 上搜索了相同的问题,并通过安装 lib"libmysqlclient-dev" 修复了它
回答by user1208639
I had similar problems with MySQL 5.6 under 64-bit Windows 7. The main solution given here worked. (the solution suggested by kobalz of just copying the dll didn't work. No idea why it works for kobalz but not for me!)
我在 64 位 Windows 7 下使用 MySQL 5.6 遇到了类似的问题。这里给出的主要解决方案有效。(kobalz 建议的仅复制 dll 的解决方案不起作用。不知道为什么它适用于 kobalz 而不适用于我!)
I then ran into another problem which is described in this post:
然后我遇到了这篇文章中描述的另一个问题:
mysql2 gem compiled for wrong mysql client library
The solution described there avoids downloading a complete 32-bit MySQL and fixed both problems. Essentially, download the mysql connector (a much smaller download) and use that to compile the mysql2 gem. You have to download exactly the right version, as described in the post. In my case:
那里描述的解决方案避免了下载完整的 32 位 MySQL 并解决了这两个问题。本质上,下载 mysql 连接器(一个小得多的下载)并使用它来编译 mysql2 gem。您必须下载完全正确的版本,如帖子中所述。就我而言:
http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick
http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick
then copy the lib\libmysql.dll file from there into your Ruby bin directory as described above.
然后如上所述将 lib\libmysql.dll 文件从那里复制到您的 Ruby bin 目录中。
I put my connector into c:\mysql-connector-c-noinstall-6.0.2-win32
我将连接器放入 c:\mysql-connector-c-noinstall-6.0.2-win32
so the command to build and install the gem was:
所以构建和安装 gem 的命令是:
gem install mysql2 -- --with-mysql-lib="c:\mysql-connector-c-noinstall-6.0.2-win32\lib" --with-mysql-include="c:\mysql-connector-c-noinstall-6.0.2-win32\include" --with-mysql-dir="c:\mysql-connector-c-noinstall-6.0.2-win32"
gem install mysql2 -- --with-mysql-lib="c:\mysql-connector-c-noinstall-6.0.2-win32\lib" --with-mysql-include="c:\mysql-connector-c -noinstall-6.0.2-win32\include" --with-mysql-dir="c:\mysql-connector-c-noinstall-6.0.2-win32"
I then ran into further problems when I ran rake to do a migration, but that was because I had been using the mysql gem (not mysql2) and I had forgotten to update my database.yml. With the mysql2 gem, it needs to say:
当我运行 rake 进行迁移时,我遇到了进一步的问题,但那是因为我一直在使用 mysql gem(不是 mysql2)并且我忘记更新我的 database.yml。用mysql2 gem,需要说:
development: adapter: mysql2
开发:适配器:mysql2
rather than
而不是
development: adapter: mysql
开发:适配器:mysql
which is obvious once you've figured it out, but the error messages I got were similar to the ones I got before, so it looked as if there was still something wrong with my gem.
一旦你弄清楚了,这很明显,但是我得到的错误消息与我之前得到的相似,所以看起来我的 gem 仍然有问题。
回答by Orsiris de Jong
This one worked for me for a MariaDB 5.5 installation:
这个对我来说适用于 MariaDB 5.5 安装:
gem install mysql2 -- '--with-mysql-lib="c:\Program Files (x86)\MariaDB 5.5\lib" --with-mysql-include="c:\Program Files (x86)\MariaDB 5.5\include\mysql"'
gem install mysql2 -- '--with-mysql-lib="c:\Program Files (x86)\MariaDB 5.5\lib" --with-mysql-include="c:\Program Files (x86)\MariaDB 5.5\包括\mysql"'
Building native extensions with: '--with-mysql-lib="c:\Program Files (x86)\Maria DB 5.5\lib" --with-mysql-include="c:\Program Files (x86)\MariaDB 5.5\include\mys ql"'
使用以下命令构建本机扩展:'--with-mysql-lib="c:\Program Files (x86)\Maria DB 5.5\lib" --with-mysql-include="c:\Program Files (x86)\MariaDB 5.5 \include\mys ql"'
Be sure to use x64 MariaDB packages if you plan to use Ruby x64. And of course, don't forget to copy C:\Program Files (x86)\MariaDB 5.5\lib\libmysql.dll to c:\Ruby200\bin in my case.
如果您打算使用 Ruby x64,请务必使用 x64 MariaDB 包。当然,在我的情况下,不要忘记将 C:\Program Files (x86)\MariaDB 5.5\lib\libmysql.dll 复制到 c:\Ruby200\bin。
回答by Omar M.
this is what worked for me on windows 8 64bit and using ruby 64bit
这就是在 windows 8 64bit 和使用 ruby 64bit 上对我有用的方法
download and install MYSQL Server 5.6 64bit
下载并安装 MYSQL Server 5.6 64bit
then run the 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"'
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 服务器 5.6\include"'
hope this helps
希望这可以帮助
回答by kobaltz
Copy the libmysql.dll located in the bin directory of your MySQL install to the bin directory of your Ruby install. Mine were located in C:\Program Files\MySQL and C:\Ruby.
将位于 MySQL 安装的 bin 目录中的 libmysql.dll 复制到 Ruby 安装的 bin 目录。我的位于 C:\Program Files\MySQL 和 C:\Ruby。