1

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 
user3694391
  • 133
  • 1
  • 2
  • 12
  • 1
    you need some mysql dev library, i don't know how it works on windows though, check this, might help http://stackoverflow.com/questions/4115126/ruby-gem-mysql2-install-failing – Mohammad AbuShady Jun 30 '14 at 20:21

1 Answers1

2

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

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • I tried that. Unfortunately, this results in undefined references to a large number of different items. I do not quite understand why that is happening. In the end, it says, "make failed. Exit code 2". The problem remains unsolved. – user3694391 Jun 30 '14 at 22:31
  • I have done what you said. However, running the installer does not give a zip file that has to be unzipped. It simply downloads the files directly. Then when I pass the correct command in the terminal, I get a huge bunch of undefined references to various items like 'mysql_error@4', 'mysql_init@4', 'mysql_num_rows@4'. Please help me. I can't figure out what's wrong here. – user3694391 Jun 30 '14 at 23:15
  • 2
    It finally worked! I had to make sure that I copied the new libmysql.dll file from the new connector to my ruby/bin and lib folders. :) – user3694391 Jun 30 '14 at 23:25