1

I'm having a bunch of problems installing the mysql2 gem on Ruby, I've tried a lot of guides, but nothing seems to be working... Here's the error when I try to install it, without any extra commands.

C:\Users\Julián>gem install mysql2 --no-rdoc --no-ri
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:/Ruby200-x64/bin/ruby.exe extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
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:/Ruby200-x64/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}/
    --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}/
    --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:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql
2-0.3.16 for inspection.
Results logged to C:/Ruby200-x64/lib/ruby/gems/2.0.0/extensions/x64-mingw32/2.0.
0/mysql2-0.3.16/gem_make.out

I'm really stumped, I tried to find a solution around here but couldn't find anything. I tried installing MySQL connectors and setting with-mysql-lib commands. Please help!

jabsatz
  • 341
  • 3
  • 10
  • This is could be helpful [click here][1] [1]: http://stackoverflow.com/questions/3608287/error-installing-mysql2-failed-to-build-gem-native-extension – user3321753 Jul 09 '14 at 09:00

2 Answers2

2

Since it appears you're using Windows, you need to consider you have to install the MYSQL C-Connector header files to get it to work

We've written a tutorial about this here

--

You'll want to use the following steps:

  1. Install the MYSQL C-Connector files (without any spaces in path)
  2. Install the MYSQL2 gem again (with correct path references)
  3. Copy lbmysql.dll to your ruby/bin folder

Firstly, you'll want to downlaod the MYSQL C-Connector files:

enter image description here

It has to be 32-bit C-Connector

Once you've installed this into a path with no spaces, you can then use the mysql2 installation command again, with config options:

gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\mysql-connector-path"'

After this, you can then transfer libmysql.dll from your mysql files to your ruby/bin directory:

enter image description here

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • Thanks man, however, on your site the pretty font for your command gem install mysql2 —platform=ruby — ‘—with-mysql-dir=”C:\mysql-connector-path”’ messes up when pasting... no biggy and +1.. thanks again. – Will Oct 09 '14 at 05:05
  • How do I specify the verison to install? `--version 0.3.16` doesn't do anything. – Matt Jul 02 '16 at 16:53
0

in a terminal.. First do a ‘locate mysql_config’ and then replace the path in the following command with where that file is.

gem install mysql2 --no-rdoc --no-ri --with-mysql-config=path

omr3421
  • 97
  • 9