How to Install gem mysql2 on Windows 8



我花了很多时间来修复并理解这个错误。每次在Windows上安装ruby on rails时,我都会遇到同样的问题。当我要安装mysql2-gem时,我得到以下错误:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
c:/Ruby193/bin/ruby.exe extconf.rb
checking for ruby/thread.h... no
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
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... 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:/Ruby193/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-mysql-config
--without-mysql-config
--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-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib

Gem files will remain installed in c:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.14 for inspection.
Results logged to c:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.14/ext/mysql2/gem_make.out
An error occurred while installing mysql2 (0.3.14), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.14'` succeeds before bundling.

我目前在Windows 7 64x上使用ruby 1.9.3p0版本

如何修复这个麻烦的错误?

介绍用mysql2-gem解决所有问题的步骤。

1-请确保您已安装mysql

2-请确保您的ruby上安装了DevKit。

3-现在下载mysql连接器http://dev.mysql.com/downloads/connector/c/(下载独立版本)

4-将其提取到任何本地目录

5-转到该目录并复制文件libmysql.dll和libmysql.lib.

6-将它们粘贴到C:\ruby193\bin 上

7-打开提示命令并运行命令

gem install mysql2 -- '--with-mysql-dir=""'

8-Voilà宝石成功安装。

希望这能帮助到别人。:)

最新更新