user3694391
user3694391

Reputation: 133

Installing mysql2 gem

I have tried installing mysql 2 gem to start building my rails app. I have Rails 4.0.4 and Ruby 1.9.3p545. I've been getting the same error after working on it for several days. I tried installing mysql 32 bit version again to make sure I had the right version with the right connector, moved my libmysql.dll and libmysql.lib to my ruby/bin folder and tried several other means of making it work that I found online. None of them have worked for me. The below is what I have. I would appreciate any help that allows me to finally install the mysql2 gem.

PS C:\Users\pc> gem install mysql2 --no-rdoc --no-ri -- '--with-mysql-lib="C:\Program Files\MySQL\
.6\lib\" --with-mysql-include="C:\Program Files\MySQL\MySQL Server 5.6\include\"'
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-lib=C:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mys
Program Files\MySQL\MySQL Server 5.6\include"'
This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    C:/Ruby193/bin/ruby.exe extconf.rb --with-mysql-lib=C:\Program Files\MySQL\MySQL Server 5.6\lib" --wit
e=C:\Program Files\MySQL\MySQL Server 5.6\include"
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=${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=${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

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.16 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/extensions/x86-mingw32/1.9.1/mysql2-0.3.16/gem_make.out 

Upvotes: 1

Views: 4573

Answers (1)

Richard Peck
Richard Peck

Reputation: 76774

We wrote a tutorial on how to do this here

--

There are several issues with what you're doing:

  1. You cannot have any spaces in the paths
  2. You need to include the latest version of MYSQL C-Connector

This works for us:

  • Download the latest 32 bit version of MYSQL C-Connector
  • Install into a path without spaces
  • Use the following command:

    gem install mysql2 --platform=ruby -- ‘--with-mysql-dir=”C:\mysql-connector-path”’

This should install it correctly

Upvotes: 2

Related Questions