Ruby MYSQL2 gem installation on windows 7
Asked Answered
K

18

35

I'm trying to installing the mysql2 gem on windows 7 I downloaded the connector from the mysql site and placed the libmysql.dll in ruby200\bin

then do gem install mysql2

These are the results am I being dim here?

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/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:/Ruby200/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}/
extconf.rb:37:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError
)


Gem files will remain installed in C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.
3.13 for inspection.
Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/ext/mysql2/g
em_make.out
Karnes answered 25/9, 2013 at 19:58 Comment(6)
As it indicates, check out: Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/ext/mysql2/g em_make.out and also mkmf.log for descriptive errors. Post them here. It probably needs headers such as by supplying "gem install mysql2 -- --with-MySQL-lib=<MySQL source file that matches the correct mod level>". These files can be downloaded to permit installation, but make sure it matches your gem's mod level. I use BitNami Rubystack on Windows 8 which includes MySQL. RailsInstaller is a very popular comprehensive install.Barrettbarrette
It may be a problem with native gem installation. Can you install other native gems like bson_ext?Pinstripe
Yeah thanks for the help guys, @R_G yeah you were right I needed to specify the locations for each of the required files via the gem command below, quite why gem install doesn't look in the same folder i'm not sure, I was trying to stay away from bundled installers as it helps me understand rails a bit better!Karnes
possible duplicate of Unable to install mysql2 gem on windows 7Renata
Read the yellow text at the top of my question. That's the reason the mysql gem nor the mysql2 gem won't install! #30361780Sacrosanct
Thanks MacGyver as per the bit in yellow this question does give an answer it's the one with 85 upvotes.... ;-)Karnes
K
108

EDIT 30/09/2014

When this answer was posted the 64 bit rails installer wasn't the recommended version - it now seems people are starting to use it more. It should be noted when you download the MySQL Connector you need to download either 64 or 32bit to correspond to the version of rails you installed.

Amazingly I lucked upon an answer very early this morning as I happened to be looking for something else of a similar nature. I'm not quite sure why there isn't a single simple guide for this as it appears to be very straight forward!

For some reason just specifying the mysql-dir when you install the gem doesn't pick up with other sub directories so you need to set the parameters manually.

For anyone else experiencing the same problem, I did the following:

1) Download the MySql C Connector from: http://dev.mysql.com/downloads/connector/c/

NOTE Don't download the installer, download the ARCHIVE for your OS

Download either the 32bit or 64 bit ARCHIVE to correspond with the version of rails you installed.

2) Extract the file to C:\mysql-connector

3) Then ran:

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

Voila everything is working fine.

EDIT 30/01/2014

I just had to do a fresh install on a bricked machine and the command in step 3 didn't work, what did work was:

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

I'm not quite sure what the difference is but this time it seems to be picking up the directories ok, so if the first one doesn't work try this one!

I think this has to do with how you go about installing rails, this time round I used the railsinstaller which seems to set the paths up correctly.

A lot of the outcome here seems to depend on the shell your using, a lot of people are having problems with powershell so I wouldn't advise using it. I did this in an elevated command prompt.

Oh and lastly if you get an error regarding the mysql2 gem when you do RAILS S you need to copy the libmysql.dll from the LIB directory of the mysql connector to the bin directory where rails has been installed.

Karnes answered 26/9, 2013 at 8:29 Comment(10)
Make sure you download 32-bit server and 32-bit connector. github.com/oneclick/rubyinstaller/wiki/…Tokenism
the second code worked using 32 bit version of mysql-connectorTwiggy
My answer below covers what happens if you have them installed as part of the Windows MySQL installer.Warrantee
Thanks man. This helped a lot. Was struggling with Rails installation on windows and mysql gem was the only issue I was facing. Thanks once again.Chopping
Addtionally, need to have Ruby DevKit installed as well. http://rubyinstaller.org/add-ons/devkit/Lemons
Thanks! This worked for me finally. I was trying to use wamp’s mysql connector itself but apparently gem was not able to access itClothes
It only worked for me after I disabled my antivirus. I have no idea why. I found this tip on a comment by David Eichel at teamtreehouse.com/forum/…Maybe
You may need to 'unblock' the zip file.Wool
the second command worked for me,i guess.But the application is still not running in my windows 8..any idea ?Understrapper
I had to delete the folders of mysql-{version} from {path-to-ruby}\lib\ruby\gems\{version}\gems, then the above solution worked for me.Summerville
M
7

I've tried the solution of @Mrk Fldig but it didn't work... So what solved the problem was:

  1. Downloaded the lastest MySQL Installer for windows 7 32 bits
  2. Installed the gem with the following command: gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/Program Files/MySQL/MySQL Connector C 6.1 6.1.2/"'

One pitfall to be aware of is that I changed the backslashes (\) to normal slashes (/). I've tried the same procedure with backslashes and it didn't work.

The installer already includes the C connectors for MySQL at MySQL Connector C 6.1 6.1.2 directory. Therefore, passing only the --with-mysql-dir parameter without the --with-mysql-lib or --with-mysql-include parameters, makes the gem to look at the same directory for the lib and include directories

Maxine answered 13/12, 2013 at 13:54 Comment(1)
This also fixes it for me. But I've just used the archive as per the above instructions. The issue seems to be what shell you're in. I'm running in the msysgit bash shell and multiple --with options seemed to fail with that. Your trick works just fine.Trinia
I
5

Steps for Ruby 2.1.3, Windows 8.1 and MySQL Server 5.7. All x64 bit.

  1. Download Development Kit
  2. Extracted Development Kit.
  3. Run CMD and go to dir where is Development Kit extracted
  4. Run ruby dk.rb init
  5. Run ruby dk.rb install
  6. Run gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.7\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.7\include" --with-mysql-dir="c:\Program Files\MySQL\MySQL Server 5.7"'
Inerney answered 9/10, 2014 at 23:18 Comment(1)
This solution worked for me on Windows 10, Ruby 2.5.5, MySQL Server 5.7 (all x64 bit). Thank you.Selfpollination
M
1

I have tried all provided methods but the same error appears again and again :(

Fortunately, older version installed without any errors!

gem uninstall mysql2
gem install mysql2 -v 0.2.6
Middleclass answered 30/5, 2014 at 12:24 Comment(1)
Fortunately, i doesn't workHydrangea
E
1

This is what worked for me for the same error on Windows 8 64-bit and using ruby 64-bit

  1. Download and install MySQL Server 5.6 64-bit
  2. Run this command:

    gem install mysql2 -v '0.3.16' -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.6\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.6\include"'
    

Hope this helps

Echino answered 12/8, 2014 at 2:11 Comment(2)
Nice to know that works too, for my project I already had a remote DB so I didn't need to install!Karnes
Incidentally as far as I know railsinstaller is 32 bit so will require 32 bit libs as per the instructions below.Karnes
P
0

Try to follow those steps:

I assume:

  • a) you use windows7
  • b) ruby 2+ on C:\Ruby200-x64
  • c) rails 4+ installed on ruby
  • d) WAMP installed on C:\wamp and running

1) uninstall your myslq2 gem:

$ gem uninstall mysql2

2) reinstall the mysql2 gem with path option:

$ gem install mysql2 -- '--with-mysql-lib="C:\wamp\bin\mysql\mysql5.6.12\lib" --with-mysql-include="C:\wamp\bin\mysql\mysql5.6.12\include"'

3) copy the libmysql.dll you find in C:\wamp\bin\mysql\mysql5.6.12\lib into C:\Ruby200-x64\bin

4) open in your rails app the file "Gemfile" and edit it enabling the mysql2, by adding:

gem 'mysql2'

5) start your rails server:

$ rails server

6) open your browser and go to localhost:3000/

Paltry answered 20/3, 2014 at 15:12 Comment(0)
T
0

I am still having problem with mysql2 gem but below approach helped me install mysql with RoR on Windows Env.

Step 1 : Gem File changes : ({app}/Gemfile)

Update mysql2 --> mysql

Step 2 : Updates in database.yml file ({app}/config/database.yml)

Change adapter: mysql2 --> adapter: mysql

host: localhost --> host: 127.0.0.1

Step 3 : Downoad mysql-connector-c-noinstall-6.0.2-win32

Step 4 : Copy mysql-connector-c-noinstall-6.0.2-win32\lib\libmysql.dll file to C:\RailsInstaller\Ruby1.9.3\bin

Step 5 :bundle update && Start rails server

Thievish answered 21/5, 2014 at 9:15 Comment(0)
U
0

Here's what worked for me:

gem install mysql2 -- '--with-mysql-dir="C:\wamp\bin\mysql\mysql5.5.xx"'

Been searching for a few hours and not seen this variation suggested, so hopefully it will help someone!

Underdone answered 31/5, 2014 at 14:50 Comment(0)
Z
0

Also try disabling your antivirus before installing the gem. Mine got installed after I ran following command :

gem install mysql2 --platform=ruby -- '--with-mysql-lib=
"C:\mysql-connector\lib" --with-mysql-include="C:\mysql-connector\include" --wit
h-mysql-dir="C:\mysql-connector"'

Same command was not working when my antivirus was enabled, as it was pushing some ruby file to chest. Hope this helps someone.

Zante answered 26/6, 2014 at 10:23 Comment(1)
THANK YOU I've been looking everywhere, but nothing was working. This worked for me.Bergquist
V
0

It worked for me after adding some tweaks

gem install mysql2 --platform=ruby -- '--with-mysql-lib="C:\Program Files\MySQL\MySQL Connector C 6.1.5\lib" --with-mysql-include="C:\Program Files\MySQL\MySQL Connector C 6.1.5\include" --with-mysql-dir="C:\Program Files\MySQL\MySQL Connector C 6.1.5"
Venitavenite answered 18/8, 2014 at 19:8 Comment(1)
Heh, yeah thats what the first option was, glad its sorted!Karnes
P
0

For Cygwin, I could consolidate various steps.

  1. Use cygwin setup.exe to download gcc, g++, make, cmake and libmysqlclient-devel (from cygwin ports)
  2. Download c/connector src for windows from mysql site. I downloaded 6.x version. OR download libmysqlclient-devel's version (not sure from where)
  3. unzip
  4. cd dir_connector
  5. Not required and RISKY, but if cygwin libmysqlclient-devel version is 5.5.40 , then change dir_connector/VERSION file's versions to 5.5.40
  6. mkdir build
  7. cd build
  8. comment dtoa in stdlib.h, else compilation is failing
  9. cmake ..
  10. make
  11. make install
  12. gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Parlor answered 14/11, 2014 at 8:12 Comment(0)
B
0

Ruby installer rubyinstaller-devkit-2.5.3-1-x64

Mysql connector: mysql-connector-c-6.1.11-win32 https://downloads.mysql.com/archives/c-c/?version=6.1.2&os=src

Gem install: gem install mysql2 --platform=ruby -- --with-mysql-lib="c:\mysql-connector-c-6.1.11-win32"

Baber answered 23/3, 2019 at 12:7 Comment(1)
Upvoted because JJJ being a bit mean there(assuming JJJ downvoted), welcome to StackOverflow generally speaking you should give me a bit more of a write up your answers, whilst the answer may be correct you should explain the steps ;-)Karnes
C
0

win 10 solution (ruby 3.1.4 devkit)

  • downloaded C connector 6.1.1 (32bit) from here
  • after that run: gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\Program Files (x86)\MySQL\MySQL Connector C 6.1"'
Corr answered 28/4, 2023 at 22:46 Comment(0)
S
-1

I downloaded the devkit 32-bit, with my 64-bit pc, however I realize that railsinstaller apparently installs a 32-bit version by default, so I have directed all facilities 32bit.

Initialize the ruby devkit dk.rb init

Download the mysql connector 32-bit, and place it in the mysql-connector C: \ mysql-connector

You should be aware, that when you unzip the file, it creates a subfolder with the same name and can give errors.

Then use the second command listed above:

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

This was the solution I found, as I had the same problem.

Suave answered 15/2, 2014 at 20:29 Comment(0)
W
-1

On Windows 7 I found that the existing answers provided a partial solution, but I still couldn't get it to install.

The problem I had was that the MySQL Community Edition Windows installer I used insisted on putting the connectors in folders called things like C:\MySQL\MySQL Connector C 6.1.3. The build process in the gem was reporting that it could not find "C:\MySQL\MySQL" ( and before that when I had it in Program Files, it complained it couldn't find "C:\Program\includes" ) so clearly the spaces were a problem and I couldn't find a way to escape them that it could understand- possibly someone will be able to suggest one of those.

Because I wasn't sure whether changing these would break the installation, once I realised why the problem was arising I just created a symlink from the command line ( something that is easier from cmd than powershell ) like this:

C:\MySQL> mklink /D ConnectorC ".\MySQL Connector C 6.1.3"

Then I could use the following install line:

 gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/MySQL/ConnectorC/"'

This worked correctly.

Also, when I tried to use it, I ran into this problem so it may be useful to be aware that moving the MySQL lib file from the C Connector lib folder could be helpful.

Warrantee answered 9/4, 2014 at 9:24 Comment(0)
C
-1

I managed to succeed at this out of pure luck, but after an hour of hell I feel like I should share my solution, obviously very shortened but a lot of the steps I think you can figure out how to do on your own.

My machine is Win 7 64bit. I was able to install version 0.3.16

  1. Install ruby version 2.0.0p481 (?)
  2. Devkit blah blah
  3. Install rails version 4.0.0
  4. Download Mysql Connector C 64 bit zip file, put in C drive as mysqlc
  5. Take DLL from that bin, put it in lib of ruby
  6. gem install mysql2 -- -- with-mysql-dir="C:\mysqlc"
Codel answered 26/7, 2014 at 21:16 Comment(0)
J
-1

None of that worked for me, until I realized that I have the 64-bit version of the DevKit installed. So I downloaded the 64-bit MySQL Connector/C from MySQL website

and installed the gem with the "with-mysql-dir" option

Jamey answered 27/9, 2014 at 12:56 Comment(0)
A
-1

Here is what I did for windows server 2012 sp2. Nothing else worked...

After receiving error 'while installing mysql2 (0.3.17), and bundler cannot continue' Make sure that 'gem install mysql2 -v '0.3.17' succeeds...

1) Download the MySql C Connector from: http://dev.mysql.com/downloads/connector/c/

2) Extract the file to C:\mysql-connector

3) gem install mysql2 -v '0.3.17' --platform=ruby -- '--with-mysql-dir="C:\mysql-connector"'

Note: the -v '0.3.17' above, it would not work without this.

4) bundle install --> Finally, Success.

Abate answered 31/5, 2016 at 14:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.