Project

General

Profile

Installing MySQL2 gem fails while running "bundle install" on Windows

Added by Alexander Prokhorov over 11 years ago

I'm installing Redmine for the first time and I don't know Ruby. I've installed Ruby 1.9.3 (2.0 is mentioned as having issues on Windows and earlier versions as deprecated), downloaded RubyMine 2.3.2, configured MySQL 5.5, configured DB connection, installed Bundler, executed bundle install --without development test, installation of JSON gem failed, installed DevKit (which is not mentioned as required on RedmineInstall), executed bundle install ... again, this time installation of MySQL2 gem failed, and I don't know how to continue.

Console log:

Installing mysql2 (0.3.13)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        C:/Apps/Ruby/Ruby193/bin/ruby.exe extconf.rb
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
*** 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:/Apps/Ruby/Ruby193/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
extconf.rb:37:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError)

Gem files will remain installed in C:/Apps/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.13 for inspection.
Results logged to C:/Apps/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.13/ext/mysql2/gem_make.out
An error occurred while installing mysql2 (0.3.13), and Bundler cannot continue.

Make sure that `gem install mysql2 -v '0.3.13'` succeeds before bundling.

Suspicious lines from mkmf.log (can C compile code with errors, not merely warnings?):

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

"gcc -o conftest -IC:/Apps/Ruby/Ruby193/include/ruby-1.9.1/i386-mingw32 -IC:/Apps/Ruby/Ruby193/include/ruby-1.9.1/ruby/backward -IC:/Apps/Ruby/Ruby193/include/ruby-1.9.1 -I. -DFD_SETSIZE=2048  -DFD_SETSIZE=2048  -O3 -fno-omit-frame-pointer -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c  -L. -LC:/Apps/Ruby/Ruby193/lib -L.      -lmsvcrt-ruby191  -lshell32 -lws2_32 -limagehlp -lshlwapi  " 
conftest.c: In function 't':
conftest.c:7:53: error: 'rb_wait_for_single_fd' undeclared (first use in this function)
conftest.c:7:53: note: each undeclared identifier is reported only once for each function it appears in

...

conftest.c: In function 't':
conftest.c:7:53: error: 'rb_intern3' undeclared (first use in this function)
conftest.c:7:53: note: each undeclared identifier is reported only once for each function it appears in

gem_make.out contains the message from the console.

The error "extconf.rb:37:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError)" refers to this code:

...

if RUBY_PLATFORM =~ /mswin|mingw/
  inc, lib = dir_config('mysql')

  # Ruby versions not incorporating the mkmf fix at
  # https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/39717
  # do not properly search for lib directories, and must be corrected
  unless lib[-3, 3] == 'lib'                                                  # !!! line 37 !!!
    @libdir_basename = 'lib'
    inc, lib = dir_config('mysql')
  end
  exit 1 unless have_library("libmysql")
elsif mc = (with_config('mysql-config') || Dir[GLOB].first) then

...

I can't understand where extconf.rb comes from as it seems to be recreated every time, and running ruby extconf.rb stops before running the problematic line, so I have no idea how to fix/debug this. Zero knowledge of Ruby and its environment doesn't help either. Googling doesn't help as this error is too generic.

Windows 7 Ultimate 64-bit (6.1 build 7601 SP1)
Ruby 1.9.3p448 (2013-06-27) [i386-mingw32]
Rails 3.2.13
MySQL 5.5.25.0

Any suggestions?


Replies (7)

RE: Installing MySQL2 gem fails while running "bundle install" on Windows - Added by Alexander Prokhorov over 11 years ago

TL;DR Done.

Found the source of the problem: GitHub: brianmario/mysql2: Pull request 'Handle dir_config returning nil, nil on Windows ( github.com/brianmario/mysql2/pull/402 )
The pull request has been merged, but it's not in the release yet. Managed to install using command gem install mysql2 -v '0.3.11'
After running bundle install I get the message "Your bundle is complete!"

However, running rake fails now:

D:\Web\~redmine>set RAILS_ENV=production

D:\Web\~redmine>rake generate_secret_token

rake aborted!
126: The specified module could not be found.   - C:/Apps/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so
D:/Web/~redmine/config/application.rb:7:in `<top (required)>'
D:/Web/~redmine/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)

D:\Web\~redmine>rake db:migrate

rake aborted!
126: The specified module could not be found.   - C:/Apps/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so
D:/Web/~redmine/config/application.rb:7:in `<top (required)>'
D:/Web/~redmine/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)

But the file is there! It turns out ( stackoverflow.com/questions/7232571/the-specified-module-could-not-be-found-mysql ) that rake is actually missing LibMySQL.dll. Okay, copied the library from my MySQL installation ("C:\Program Files\MySQL\MySQL Server 5.5\lib\libmysql.dll"). A new message appears which is even more awesome:

rake aborted!
193: %1 is not a valid Win32 application.   - C:/Apps/Ruby/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so

It turns out ( stackoverflow.com/questions/1208029/193-1-is-not-a-valid-win32-application-bug-with-a-new-rails-application) what rake actually means is that it wants 32-bit LibMySQL.dll. Okay, downloaded the library from the link suggested in the answer. A new message appears which is the least cryptic and most meaningful of all I've seen so far:

rake aborted!
Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.0.27.

...

RE: Installing MySQL2 gem fails while running "bundle install" on Windows - Added by Alexander Prokhorov over 11 years ago

...

The funny thing is that MySQL 6.0 hasn't been invented yet. It turns out ( stackoverflow.com/questions/8740868/mysql2-gem-compiled-for-wrong-mysql-client-library ) what rake actually means is that it needs a version from MySQL C Connector. Long story short, what I've actually need to do is to go to dev.mysql.com/downloads/connector/c/6.0.html (exactly this version, not the latest one), download "Windows (x86, 32-bit), ZIP Archive" and extract libmysql.dll to Ruby bin directory.

DONE!

Well... almost. Now I have to finish the quest of running it under Apache... Which promises to be even more fun ( redmine.org/projects/redmine/wiki/HowTo_Install_Redmine_in_a_sub-URI_on_Windows_with_Apache )

Now I understand why people say that installing Redmine is horror (and why Ruby sucks on Windows too).

P.S. I can't post links or long messages. The forum returns "internal error" when I try to post them.

RE: Installing MySQL2 gem fails while running "bundle install" on Windows - Added by Matthew Houston over 11 years ago

Oh man, the pain with this install!!! I have an existing 2.1.2 installation that I'm trying to upgrade with some new features. Luckily I went through the whole mySQL lib fiasco earlier. To solve it in an upgrade context I did below.

Funny thing is I had just tested 2.3.1 and the installation went through without a damned hiccup! Then 2.3.2 was released in the time between test and implement so I thought I could just skip the point release and upgrade to the latest, geez what a pain!

How I got around these issues was:

  • edit the gemfile
  • Remove the whole section regarding the database connectors
  • At the end of the file add - gem "mysql2", "0.3.11"
  • Run bundle install --without test developement rmagick

Then db:migrate was working fine... WHEW!

EDIT : Looking back at it now, it's probably safe to only edit the gemfile to change the lines version info for the mysql adapter from "~> 0.3.11" to just "0.3.11" and it would have the same result.

Wow what a drama!

RE: Installing MySQL2 gem fails while running "bundle install" on Windows - Added by geek guo over 11 years ago

Hi,
I also met the same problem.I modified the Gemfile file, gem ”mysql2“,"~> 0.3.11" as gem ”mysql2“,"= 0.3.11",the problem is resolved and bundler install works.

5.jpg (31.8 KB) 5.jpg

RE: Installing MySQL2 gem fails while running "bundle install" on Windows - Added by robert luo over 10 years ago

i'm got same issues, and use follow steps:

1. Download the the newest mysql-connector to c:\mysql-connector folder
2. run cmmand:
gem install mysql2 -- '--with-mysql-include="C:\mysql-connector\include" --with-mysql-lib="C:\mysql-connector\lib"'

then it works ok!

RE: Installing MySQL2 gem fails while running "bundle install" on Windows - Added by Aleksandar Pavic about 9 years ago

The solution is to install mysql development lib.

On Ubuntu it's

sudo apt-get install libmysqld-dev

    (1-7/7)