Unable to install MySQL2 gem on Windows 7

2019-01-09 03:55发布

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

I am using 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

7条回答
Evening l夕情丶
2楼-- · 2019-01-09 03:57

Start with 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.)

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.

The gem command needs a path without spaces, so use 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:

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.)

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.

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.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-09 04:00

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.

查看更多
三岁会撩人
4楼-- · 2019-01-09 04:00

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.

查看更多
Bombasti
5楼-- · 2019-01-09 04:00
  1. install 32 bit mysql connector/c get it at here
  2. copy libmysql.dll from the directory that you install the connector/c to the %installed ruby directory%/bin/

then reinstall the gem again.

查看更多
劳资没心,怎么记你
6楼-- · 2019-01-09 04:07

I've tried the solution of @Mrk Fldig but it didn't work... So what solved the problem was:

  1. Downloaded the lastest MySQL Installer for windows 7 32 bits
  2. 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/"'

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.2 directory. Therefore, passing only the --with-mysql-dir parameter without the --with-mysql-lib or --with-mysql-include parameters, makes the gem to look at the same directory for the lib and include directories

查看更多
Explosion°爆炸
7楼-- · 2019-01-09 04:09

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.

Please install mysql2 gem without indicating the version:

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.

If you 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:

http://rubyinstaller.org/downloads

And follow the DevKit installation instructions from our wiki (that is linked from the download page)

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:

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 subst to avoid issues with path with spaces, which you should avoid always.

Hope this helps.

查看更多
登录 后发表回答