mysql ruby gem not installing on Windows 7

2019-07-23 15:33发布

问题:

Not a duplicate. This question is mysql gem and the other question is mysql2 gem. They do have the same answer though, but the other question's answer doesn't tell what the solution is explicitly. The answer is hidden in the comments. See yellow text of the answer for this question contains the solution.

Below is an error I'm receiving when trying to install the mysql gem on Windows.

C:\>gem install mysql
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
        ERROR: Failed to build gem native extension.

    C:/Ruby22-x64/bin/ruby.exe -r ./siteconf20150520-7968-hbly9l.rb extconf.rb
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:/Ruby22-x64/bin/$(RUBY_BASE_NAME)
        --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:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql-
2.9.1 for inspection.
Results logged to C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0
/mysql-2.9.1/gem_make.out

How did I get to this point?

  1. Installed MySQL for Windows.

http://dev.mysql.com/downloads/windows/installer/

  1. Installed Python for Windows. This step probably has nothing to do with my error, but I'm including it since it is required for the build I'm deploying.

https://www.python.org/downloads/

  1. Installed Ruby for Windows. Looks like I downloaded the "rubyinstaller-2.2.2-x64.exe and installed that.

http://rubyinstaller.org/downloads/

  1. Installed Ruby Gems. Looks like I downloaded and extracted "rubygems-2.4.7.zip".

https://rubygems.org/pages/download

Then ran these commands from the Windows command prompt:

gem update --system

... was installed in C:/Ruby22-x64/bin/gem

gem install rubygems-update

update_rubygems

... then cd {folder extracted zip to}

ruby setup.rb
  1. Then I tried installing the mysql gem like so. And got an error.

    C:>gem install mysql Fetching: mysql-2.9.1.gem (100%) ERROR: Error installing mysql: The 'mysql' native gem requires installed build tools.

    Please update your PATH to include build tools or download the DevKit from 'http://rubyinstaller.org/downloads' and follow the instructions at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

  2. So I followed the instructions. I went to that page (http://rubyinstaller.org/downloads). Looks like I downloaded "DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe". When I extracted the stupid extractor put the files in the same directory with everything else. So make sure you make a new folder after downloading, and before extracting.

Then I ran this command.

ruby dk.rb init

Then I ran this command, and got an error.

ruby dk.rb install

I had to make sure the "config.yml" file pointed to the C:\Ruby22-x64 folder on my machine for where Ruby was installed. I removed the comment and change the path. Then reran the command, and it worked.

ruby dk.rb install

Then ran this command.

gem install rdiscount --platform=ruby
  1. Then tried to re-install the mysql gem. And got the error in my question. What a gem! "I got you jewels Betty, jewels!"

    gem install mysql

EDIT 5/21/2015:

Per the question below, I'm getting a new error.

Ruby MYSQL2 gem installation on windows 7

C:\>gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\mysql-connector\
lib" --with-mysql-include="C:\mysql-connector\include" --with-mysql-dir="C:\mysq
l-connector"'
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-mysql-lib="C:\mysql-connector\lib" --wi
th-mysql-include="C:\mysql-connector\include" --with-mysql-dir="C:\mysql-connect
or"'
This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    C:/Ruby22-x64/bin/ruby.exe -r ./siteconf20150521-10824-1plgdr8.rb extconf.rb
 --with-mysql-lib="C:\mysql-connector\lib" --with-mysql-include="C:\mysql-connec
tor\include" --with-mysql-dir="C:\mysql-connector"
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using --with-mysql-dir=C:\mysql-connector\include;C:\mysql-connector\include;C:\
mysql-connector
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... 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:/Ruby22-x64/bin/$(RUBY_BASE_NAME)
        --with-mysql-dir
        --with-mysql-include=${mysql-dir}/include
        --with-mysql-lib=${mysql-dir}/lib
C:/Ruby22-x64/lib/ruby/2.2.0/rake/task_manager.rb:62:in `[]': Don't know how to
build task 'C:/mysql-connector/lib;C:/mysql-connector/lib;C:/mysql-connector/lib
/libmysql.lib' (RuntimeError)
        from C:/Ruby22-x64/lib/ruby/2.2.0/rake/task.rb:57:in `lookup_prerequisit
e'
        from C:/Ruby22-x64/lib/ruby/2.2.0/rake/task.rb:53:in `block in prerequis
ite_tasks'
        from C:/Ruby22-x64/lib/ruby/2.2.0/rake/task.rb:53:in `map'
        from C:/Ruby22-x64/lib/ruby/2.2.0/rake/task.rb:53:in `prerequisite_tasks
'
        from C:/Ruby22-x64/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisi
tes'
        from C:/Ruby22-x64/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_w
ith_call_chain'
        from C:/Ruby22-x64/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
        from C:/Ruby22-x64/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_
chain'
        from C:/Ruby22-x64/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
        from extconf.rb:117:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/mysql2
-0.3.18 for inspection.
Results logged to C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0
/mysql2-0.3.18/gem_make.out

C:\>

回答1:

The 'mysql' and 'mysql2' packages/extensions/gems don't work with the x64 bit version of Ruby on Windows 7 (or any 64 bit version of Windows). You need to install the x86 (32) bit version of Ruby for them to work.

So I repeated step 3 in my question, and installed version 1.9 instead taking the advice from my comment in my question (on issue 191) by luislavena on August 30, 2013. This is the x86 (32 bit) version. Got it from here.

http://rubyinstaller.org/downloads/

Looks like the file's name is "rubyinstaller-1.9.3-p551.exe".

Then completed step 4. The Ruby developers must have fixed their scripts to modify the config.yml file automatically for the x86 version. I didn't have to edit this time.

Then for step 5, I installed this devkit exe, because the newer version of Ruby didn't have a dev kit that was x86.

For step 6, I placed into it's own folder. It still extracts files in the exe root, not a folder of the exe root. Then ran all the commands except for the last one. It still threw the error.

"DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe"

Then for step 7, I ran this.

gem install mysql

It installed the x86 version of mysql gem, because I can see the gem, by running this. It's very shiny and looks expensive!

gem list

5/26/2015 update:

Latest version of Ruby when installed on Windows that allows you to start the Rails server is 2.1.6.

Starting the rails server didn't work by running "rails s". I had to go back and uninstall old versions of Ruby. See my answer here. Ignore the other answers if you are on Windows.

Remove older versions of Ruby (on Windows)

The only stable version of Ruby on Windows that allows you to start the rails server is "rubyinstaller-2.1.6.exe". "rubyinstaller-2.2.2.exe" throws the following error:

C:/row/Ruby22/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.6.2-x86-mingw32/lib/nokogiri
.rb:29:in `require': cannot load such file -- nokogiri/nokogiri (LoadError)
        from C:/row/Ruby22/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.6.2-x86-mingw32
/lib/nokogiri.rb:29:in `rescue in <top (required)>'
... 
... continued