Skip to content

Error installing mysql2, Failed to build gem native extension. On Win XP with Ruby 2.0.0. #364

Closed
wzup opened this Issue Mar 24, 2013 · 29 comments
@wzup
wzup commented Mar 24, 2013

I cannot install the gem.

I have pre-installed MySQL here, no any spaces in the path:
C:\mysql-5.6.10\mysql-5.6.10-win32

I have Ruby 2.0.0 from RubyInstaller.

The command I type:
C:\>gem install mysql2 --platform=ruby -- --with-mysql-dir="C:\mysql-5.6.10\mysql-5.6.10-win32"

Readme.md says:

If you have installed MySQL to a non-standard location, add
gem install mysql2 --with-mysql-config=/some/random/path/bin/mysql_config

What is /some/random/path/bin/mysql_config? I don't have any mysql_config file in bin/ directory of my MySQL installation. Could you explain what config is meant?

A copy/paste part from the error message:

ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    C:/Ruby200/bin/ruby.exe extconf.rb --with-mysql-dir=C:\mysql-5.6.10\mysql-5.6.10-win32
checking for rb_thread_blocking_region()... *** 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/bin/ruby

What do all those configuration options mean? Do I have to pass any values with them for successful installation? Readme.md file doesn't provide info about them. Where may I find explanation?

  1. How to solve the issue?
  2. Is it even possible to install the gem on Win XP?
@jopich
jopich commented Mar 27, 2013

+1 for me during redmine installation process.
I am under windows XP with Ruby 2.0.0 and DevKit installed as well.
I use Wamp server for mysql.

- when I try to do the "rake generate_secret_token" (from redmine install guide), I got "rake aborted! cannot load such file -- mysql2/2.0/mysql2"
- and when I try to re build mysql2 using --platform=ruby, I got the same message as wzup.

Thanks for your help

Antoine

@casoetan
casoetan commented Apr 3, 2013

Download mysql connector for c from hear http://dev.mysql.com/downloads/connector/c/ extract to a directory and then

C:\>gem install mysql2 --platform=ruby -- --with-mysql-dir="C:\path\to\where\you\extracted\my\sql\c\connector"

That should install it

@andresclari

Here's what I'm doing and seems to work fine:

After extracting the MySQL C connector:

gem install mysql2 --platform=ruby -- '--with-mysql-include=C:\Devel\mysql-connector-c-noinstall-6.0.2\include --with-mysql-lib=C:\Devel\mysql-connector-c-noinstall-6.0.2\lib --with-mysql-dir=C:\Devel\mysql-connector-c-noinstall-6.0.2'

This will successfully build the gem.
If you get a cannot load mysql.so afterwards, copy the libmysql.dll to Ruby/bin

@pkubryk
pkubryk commented Apr 10, 2013

Hi,

I tried the above commands :
C:/Work/newArch/Ruby200/bin/ruby.exe extconf.rb --with-mysql-lib=X:\lib --wi
th-mysql-include=X:\include --with-mysql-dir=X:

With x: C:\Program Files\MySQL\MySQL Connector C 6.0.2

but I got the following error

checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... 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:/Work/newArch/Ruby200/bin/ruby
--with-mysql-dir
--with-mysql-include=${mysql-dir}/include
--with-mysql-lib=${mysql-dir}/
--with-libmysqllib
--without-libmysqllib

Gem files will remain installed in C:/Work/newArch/Ruby200/lib/ruby/gems/2.0.0/g
ems/mysql2-0.3.11 for inspection.
Results logged to C:/Work/newArch/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11
/ext/mysql2/gem_make.out

the mkmf.log looks like :
have_func: checking for rb_thread_blocking_region()... -------------------- yes

"gcc -o conftest.exe -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/i386-mingw32 -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/ruby/backward -IC:/Work/newArch/Ruby200/include/ruby-2.0.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -LC:/Work/newArch/Ruby200/lib -L. -lmsvcrt-ruby200 -lshell32 -lws2_32 -limagehlp -lshlwapi "
checked program was:
/* begin /
1: #include "ruby.h"
2:
3: #include
4: #include
5: int main(void) {return 0;}
/
end */

"gcc -o conftest.exe -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/i386-mingw32 -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/ruby/backward -IC:/Work/newArch/Ruby200/include/ruby-2.0.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -LC:/Work/newArch/Ruby200/lib -L. -lmsvcrt-ruby200 -lshell32 -lws2_32 -limagehlp -lshlwapi "
conftest.c: In function 't':
conftest.c:9:1: warning: 'rb_thread_blocking_region' is deprecated (declared at C:/Work/newArch/Ruby200/include/ruby-2.0.0/ruby/intern.h:830)
checked program was:
/* begin /
1: #include "ruby.h"
2:
3: #include
4: #include
5:
6: /
top/
7: int main(void) {return 0;}
8: extern int t(void);
9: int t(void) { void ((
volatile p)()); p = (void (()()))rb_thread_blocking_region; return 0; }
/
end */


have_func: checking for rb_wait_for_single_fd()... -------------------- yes

"gcc -o conftest.exe -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/i386-mingw32 -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/ruby/backward -IC:/Work/newArch/Ruby200/include/ruby-2.0.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -LC:/Work/newArch/Ruby200/lib -L. -lmsvcrt-ruby200 -lshell32 -lws2_32 -limagehlp -lshlwapi "
conftest.c: In function 't':
conftest.c:9:57: error: 'rb_wait_for_single_fd' undeclared (first use in this function)
conftest.c:9:57: note: each undeclared identifier is reported only once for each function it appears in
checked program was:
/* begin /
1: #include "ruby.h"
2:
3: #include
4: #include
5:
6: /
top/
7: int main(void) {return 0;}
8: extern int t(void);
9: int t(void) { void ((
volatile p)()); p = (void (()()))rb_wait_for_single_fd; return 0; }
/
end */

"gcc -o conftest.exe -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/i386-mingw32 -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/ruby/backward -IC:/Work/newArch/Ruby200/include/ruby-2.0.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -LC:/Work/newArch/Ruby200/lib -L. -lmsvcrt-ruby200 -lshell32 -lws2_32 -limagehlp -lshlwapi "
conftest.c: In function 't':
conftest.c:9:1: warning: implicit declaration of function 'rb_wait_for_single_fd'
checked program was:
/* begin /
1: #include "ruby.h"
2:
3: #include
4: #include
5:
6: /
top/
7: int main(void) {return 0;}
8: extern int t(void);
9: int t(void) { rb_wait_for_single_fd(); return 0; }
/
end */


have_library: checking for main() in -llibmysql... -------------------- no

"gcc -o conftest.exe -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/i386-mingw32 -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/ruby/backward -IC:/Work/newArch/Ruby200/include/ruby-2.0.0 -I. -IX:\include -IX:/include -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -LC:/Work/newArch/Ruby200/lib -LX:\lib -LX:/ -L. -lmsvcrt-ruby200 -llibmysql -lshell32 -lws2_32 -limagehlp -lshlwapi "
c:/work/newarch/devkit/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -llibmysql
collect2: ld returned 1 exit status
checked program was:
/* begin /
1: #include "ruby.h"
2:
3: #include
4: #include
5:
6: /
top/
7: int main(void) {return 0;}
8: extern int t(void);
9: int t(void) { void ((
volatile p)()); p = (void (()()))main; return 0; }
/
end */

"gcc -o conftest.exe -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/i386-mingw32 -IC:/Work/newArch/Ruby200/include/ruby-2.0.0/ruby/backward -IC:/Work/newArch/Ruby200/include/ruby-2.0.0 -I. -IX:\include -IX:/include -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -LC:/Work/newArch/Ruby200/lib -LX:\lib -LX:/ -L. -lmsvcrt-ruby200 -llibmysql -lshell32 -lws2_32 -limagehlp -lshlwapi "
c:/work/newarch/devkit/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -llibmysql
collect2: ld returned 1 exit status
checked program was:
/* begin /
1: #include "ruby.h"
2:
3: #include
4: #include
5:
6: /
top/
7: int main(void) {return 0;}
8: extern int t(void);
9: int t(void) { main(); return 0; }
/
end */


@sodabrew
Collaborator

@pkubryk You aren't supposed to run that extconf.rb command line yourself, but rather, the gem install command. Several examples are provided in this thread, e.g. (all on one line)

gem install mysql2 --platform=ruby -- 
  --with-mysql-include=X:\mysql-connector-c-noinstall-6.0.2\include
  --with-mysql-lib=X:\mysql-connector-c-noinstall-6.0.2\lib
  --with-mysql-dir=X:\mysql-connector-c-noinstall-6.0.2
@pkubryk
pkubryk commented Apr 11, 2013

My mistake, I was tired and I copied the result of the command, not the one I ran.
I did : gem install mysql2 --platform=ruby --
--with-mysql-include=X:\include
--with-mysql-lib=X:\lib
--with-mysql-dir=X:\

Where X: has been set to the path of the connector downloaded from http://dev.mysql.com/downloads/connector/c/

@sodabrew
Collaborator

Oh, and still received the error. Hmm. [insert I-don't-have-windows-handy comment here]

@DHB
DHB commented Apr 11, 2013

Ruby 2.0.0 needs mingw64-32-4.7.2 gcc.

http://rubyinstaller.org/downloads/

@jopich
jopich commented Apr 18, 2013

Hi,

I tried everything given here :

  • Download sql connector
  • install mingw and set vars (execute devkitvars.bat)

and tried the following command
gem install mysql2 --platform=ruby -- '--with-mysql-include=C:\Devel\mysqlconnector-6.0.2\include --with-mysql-lib=C:\Devel\mysqlconnector-6.0.2\lib --with-mysql-dir=C:\Devel\mysqlconnector-6.0.2'

I am still getting the same error :

Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-include=C:\Devel\mysqlconnector-6.0.2\include --with-mysql-lib=C:\Devel\mysqlconnector-6.0.2\lib --with-mysql-dir=C:\Devel\mysqlconnector-6.0.2'
This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.

C:/Ruby200/bin/ruby.exe extconf.rb --with-mysql-include=C:\Devel\mysqlconnector-6.0.2\include --with-mysql-lib=C:\Devel\mysqlconnector-6.0.2\lib --with-mysql-dir=C:\Devel\mysqlconnector-6.0.2

checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... 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:/Ruby200/bin/ruby
--with-mysql-dir
--with-mysql-include=${mysql-dir}/include
--with-mysql-lib=${mysql-dir}/
--with-libmysqllib
--without-libmysqllib

Gem files will remain installed in C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.
3.11 for inspection.
Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/ext/mysql2/g
em_make.out

I guess I missed something with mingw.
How can I do ?

Thanks in advance

Antoine

@sodabrew
Collaborator

I'll see about getting a Windows VM up soon. Patches welcome if anybody on this thread can nail down any code or documentation changes that mysql2 needs in the repo.

@casoetan

I just uninstalled mysql2 and reinstalled it and it works still. make sure you are linking to the directory properly (where the mysql connector you downloaded is (the include and lib dir)) also copy libmysql.dll to your ruby bin directory.
Hope it works for you now

@phungnc
phungnc commented May 4, 2013

I followed andresclari's comment (gem install CLI) and casoetan's comment (copy libmysql.dll from mysql-connector folder to ruby bin directory), and It work fine! Thanks

@chrismapes

Just as a note to people with errors who are following casoetan's advice: remember that spaces in the command line need to be encapsulated with quotes. As an example for me:

gem install mysql2 --platform=ruby -- '--with-mysql-include="C:\Program Files\MySQL\MySQL Connector C 6.1\include" --with-mysql-lib="C:\Program Files\MySQL\MySQL Connector C 6.1\lib" --with-mysql-dir="C:\Program Files\MySQL\MySQL Connector C 6.1"'

If you don't encapsulate your spaces, you will end up with an error.

@ritcheyer

I'm getting this same error message as all of you, but I'm on a Mac (10.8), using Rails4 and Ruby2 and RubyMine (IDE).

/Users/eric/.rvm/rubies/ruby-2.0.0-p195/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/eric/Rubymine/Chroma/bin/bundle install
Fetching gem metadata from https://rubygems.org/........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
...
...
...
Installing mysql2 (0.3.11) 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /Users/eric/.rvm/rubies/ruby-2.0.0-p195/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... 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... yes
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
    --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=/Users/eric/.rvm/rubies/ruby-2.0.0-p195/bin/ruby
    --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


Gem files will remain installed in /Users/eric/.rvm/gems/ruby-2.0.0-p195@global/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/eric/.rvm/gems/ruby-2.0.0-p195@global/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.

Process finished with exit code 5

I have tried a number of other things from around the web as well:

  • Running gem install mysql2 from the command line gets me the same message as above.
  • Running gem 'mysql2' gets me this error: ERROR: While executing gem ... (Gem::CommandLineError) Unknown command mysql2 even though I have it it my Gemfile: http://d.pr/n/jc3i
  • I have tried adding rvm install libmysql-ruby hoping that would fix it.. nope..

I should mention this is my first real foray into RoR, so it's quite possible I'm the problem... I've looked all over StackOverflow and haven't really had any luck there either. Any help would be greatly appreciated.

@ritcheyer

Update - In starting a question on SO, this article popped up which I hadn't found before.

The resolution for me was found in this answer:
1. brew install mysql
2. gem install mysql

After this, I was able to complete the bundling process and start my application.

@sodabrew
Collaborator

Just a reminder one would be rewarded with much praise and thanks for submitting a pull request with any code or documentation changes needed to resolve this issue.

@anthonyalmighty

For everyone who is suffering though this on Mac, I've created a ticket here #383 UPDATE resolved the issue and updated the ticket. Hope this helps.

@monban
monban commented Jul 10, 2013

The problem appears when ext/extconf.rb on line 32 calls have_library("libmysql"). mkmf's have_library function looks for the specified library and tries to find a main() function in it. have_library does not reference the current compile context, nor does it look in the ruby/bin directory. It looks in ruby/lib. So this problem can be resolved by copying libmysql.dll from your mysql or mysql connector library into ruby/lib before attempting gem install.

mysql2 only needs this file to be in the lib directory during compilation. I have deleted it after the fact and everything continues to run quite happily. We DO need to run have_library on it so it gets included at link time, but I wonder if we can convince have_library to look elsewhere for it? I shall investigate further.

UPDATE: @andresclari had it right 3 months ago, if you specify --with-mysql-include and --with-mysql-lib separately (then you won't need --with-mysql-dir) it will work without libmysql.dll being in ruby/lib. The reason it wasn't working for @pkubryk was spaces in his path, the reason it didn't work for @jopich is he was using \ instead of / file separators. I still wonder if, when specifying --with-mysql-dir we can't get it to automatically add /lib as a library include directory, so I'm not quite done on this one yet.

@monban
monban commented Jul 10, 2013

Okay so final update for now, what we are seeing here is a manifestation of Bug #8074 in Ruby. There is a resolution for it, but it's not in the latest version of Ruby from rubyinstaller.org. We can either wait until they release a new Ruby and hope people upgrade, or we can apply PR #393 which fixes it on broken mkmf versions and gracefully degrades in the future.

In the mean time, either (use both the --with-mysql-lib AND --with-mysql-include) OR put libmysql.dll in your ruby/lib directory before you attempt to compile this gem.

@sodabrew
Collaborator

Merged #393

@sodabrew sodabrew closed this Jul 24, 2013
@fernandosouzs

Actually, what is wrong is how we are writing!
It's necessary to be =

gem install mysql2 --platform=ruby -- '-
-with-mysql-dir="C:\Program Files (x86)\Java\mysql-connector-c-6.1.3-winx64"'

1st, you have to put all this [-
-with-mysql-dir="C:\Program Files (x86)\Java\mysql-connector-c-6.1.3-winx64"] inside simple quotes --> ' '

2nd, if you have spaces in your dir path, you have to put inside double quotes --> " "

DONE!

@basvijfwinkel-tl

The following stepsworked for me :
1. The mysql-connector is extracted to c:\mysql-connector folder (if you open that folder you will see the 'lib', 'docs','include' and 'bin' folder.
2. For certainty I also copied the 'libmysql.dll' to my ruby bin folder (C:\RailsInstaller\Ruby1.9.3\bin)
3. execute the following command inside your project folder

gem install mysql2 --platform=ruby -v '0.3.14' -- '--with-mysql-include=C:\mysql-connector\include --with-mysql-lib=C:\mysql-connector\lib'

Specifying the 'with-mysql-dir' parameter also seemed to break the install.

@jonahx
jonahx commented Mar 29, 2014

If, after getting the gem installed, anyone else is getting an error like Incorrect MySQL client library version! This gem was compiled for 6.1.3 but the client library is 5.5.8. (RuntimeError), simply copy libmysql.dll from the connector/lib folder to your /bin folder.

@chrismapes

Just to follow up on this thread, if you're trying to install Ruby on windows: Make your life easy and use "RubyInstaller". That or go the smart but harder route of using Vagrant/Virtualbox to create an Ubuntu virtual machine and use apt-get to install RVM and use RVM to manage your Ruby installation. It's worth the trouble. That way your development machine will very closely match your production environment. For extra credit, use Docker containers on top of Vagrant so you can directly deploy the whole environment (Ruby/Rails app + OS environment) in one swoop.

This is the best solution I have found.

@simi
simi commented Jun 2, 2014

You can also help with testing windows precompiled binaries - http://gems.apicko.cz/mysql2/

@Paylon
Paylon commented Jun 30, 2014

I used these steps:

  1. The mysql-connector is extracted to c:\mysql-connector folder (if you open that folder you will see the 'lib', 'docs','include' and 'bin' folder.
  2. For certainty I also copied the 'libmysql.dll' to my ruby bin folder (C:\RailsInstaller\Ruby1.9.3\bin)
  3. execute the following command inside your project folder

gem install mysql2 -- '--with-mysql-include="C:\mysql-connector\include" --with-mysql-lib="C:\mysql-connector\lib"'
Specifying the 'with-mysql-dir' parameter also seemed to break the install.

!!!ATTENTION!!! It worked for me only if I use "" around path( example: "C:\mysql-connector\include" )

@kitximuak

gem install mysql2 -- --with-mysql-dir=C:\mysql-connector\include

It worked for me only if I use the path C:\mysql-connector\include

@kitximuak

gem install mysql2 -- --with-mysql-dir=C:\mysql-connector

It worked for me only if I use the path C:\mysql-connector

@giathinh910

Thank @chrismapes. I try many command to install mysql2 with mysql connector C but none of them work. Yours work perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.