-2

I recently installed Ruby on rails and MySQL. The versions are ruby 2.1.7 and MySQL Workbench 6.3 CE. I typed gem install mysql2 -v=0.2.6 and this happened;

Fetching: mysql2-0.2.6.gem <100%>
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
       Error: Failed to build gem native extensions.

    C:/Ruby21/bin/ruby.exe extconf.rb
checking for rb_thread_blocking_region()... yes
checkimg 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 option:
    --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=.
    --curdit
    --ruby=C:Ruby21/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

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby21/lib/ruby/gems/2.1.0/gems/mysql2-0.2
.6 for inspection.
Results logged to C:/Ruby21/lib/ruby/gems/2.1.0/extensions/x86-mingw32/2.1.0/mys
ql2-0.2.6/gem_make.out

Can anyone help me connect Ruby on rails with MySQL please?

Eric Platon
  • 9,819
  • 6
  • 41
  • 48

1 Answers1

0

from https://github.com/brianmario/mysql2 :

Linux and other Unixes

You may need to install a package such as libmysqlclient-dev or mysql-devel; refer to your distribution's package guide to find the particular package. The most common issue we see is a user who has the library file libmysqlclient.so but is missing the header file mysql.h -- double check that you have the -dev packages installed.

The correct solution will depend on your OS. Since mysql2 code is partially written in C, you need some library files installed on your system to install it.

Community
  • 1
  • 1
floum
  • 1,149
  • 6
  • 17
  • when I type `ruby -v` , outcome is `ruby 2.1.7p400 <2015-08-18 revision 51632> [i386-mingw32]` .. and when `gem -v`, outcome is `2.2.5`, It means dev packages are installed right? – idontknowhowto Jan 30 '16 at 05:12
  • It simply means that ruby is installed, but you need libmysqlclient.so which is not shipped with ruby. You can get it with your package manager (`apt-get` in debian-based distribution for example). – floum Jan 31 '16 at 09:51