tiiin4
tiiin4

Reputation: 539

How to install mysql2 gem on Windows

I'm using DevKit and XAMPP, and now I have to execute the following command:

gem install mysql2 -v 0.2.6 --platform=ruby -- --with-mysql-dir="x:\Prog
ram Files\mysql-5.5.11-winx64" --with-mysql-lib="x:\Program Files\mysql-5.5.11-winx64\lib" --with-my
sql-include="x:\Program Files\mysql-5.5.11-winx64\include" --without-opt-dir

However, XAMPP does not include a lib or include folder on its MySQL directory. What should I specify instead ?

Thanks

Upvotes: 3

Views: 12646

Answers (8)

Cereal
Cereal

Reputation: 3839

With RubyInstaller2, and the MSYS toolchain, all you have to do to install the mysql2 gem is gem install mysql2 --platform=ruby

This will automatically download and install the required libraries, and then build the gem from source.

Upvotes: 0

Erwin Kaddy
Erwin Kaddy

Reputation: 967

Thanks nick. I got it working too on my windows 8 (64bit). I got MySQL connector from this page: http://dev.mysql.com/downloads/connector/c/. Download and Run the installer. After that use the command below:

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

Now it's working

Upvotes: 1

André Herculano
André Herculano

Reputation: 1307

What solved my 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

Upvotes: 3

user674158
user674158

Reputation: 221

You may copy libmysql.dll from the lib subdirectory of your MySQL or MySQL connector directory into your ruby\bin directory ,and libmysql.dll would be located at c:\mysql-connector-c-6.1.1-win32\lib.

Upvotes: 0

Corin
Corin

Reputation: 2457

Here's the solution I used to get Ruby with the MySQL2 gem running on Windows 7 using XAMPP's MySQL installation.

At the Ruby command prompt run (make sure to update the path to wherever you've got XAMPP/MySQL installed):

gem install mysql2 -- --with-mysql-dir="C:\xampp\mysql\bin"

The output from this command includes:

=========================

You've installed the binary version of mysql2. It was built using MySQL Connector/C version 6.0.2. It's recommended to use the exact same version to avoid potential issues.

At the time of building this gem, the necessary DLL files where available in the following download:

http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-6.0.2-win32.zip/from/pick

And put lib\libmysql.dll file in your Ruby bin directory, for example C:\Ruby\bin

=========================

That is very important. Follow the instructions. Download the file, extract the libmysql.dll from the lib directory within the zip file. Copy said dll into the bin folder for your Ruby install. If you used RailsInstaller and selected the defaults, the directory will be something like C:\RailsInstaller\Ruby1.9.3\bin.

Upvotes: 6

konung
konung

Reputation: 7038

Here is a proper solution for anyone interested, that doesn't mess up your current installation of mysql server

  1. Download a zip file with mysql server 5.1 NOT the msi one. Make sure it's 32-bit NOT 64-bit. (From here)
  2. Since there is no installer file with this, create a folder c:\mysql-gem-install - you can remove it once you finish.
  3. Extract all the files from the zip file into the folder you just created.
  4. now run this command

    gem install mysql2 -- '--with-mysql-lib="c:\mysql-gem-install\lib\opt" --with-mysql-include="c:\mysql-gem-install\include"'

I just installed mysql2 gem v. 0.3.7

Upvotes: 4

tiiin4
tiiin4

Reputation: 539

I found the solution here:

rails 3 not working with windows 7

Upvotes: 3

bassneck
bassneck

Reputation: 4043

I'm not sure, how XAMPP is organized, but to build the gem, you could download the same version of mysql from their site and point devkit there. After that, the gem should work fine with XAMPP as well.

Upvotes: 0

Related Questions