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-d开发者_如何学JAVAir
However, XAMPP does not include a lib
or include
folder on its MySQL directory. What should I specify instead ?
Thanks
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.
Here is a proper solution for anyone interested, that doesn't mess up your current installation of mysql server
- Download a zip file with mysql server 5.1 NOT the msi one. Make sure it's 32-bit NOT 64-bit. (From here)
- Since there is no installer file with this, create a folder c:\mysql-gem-install - you can remove it once you finish.
- Extract all the files from the zip file into the folder you just created.
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
I found the solution here:
rails 3 not working with windows 7
What solved my problem was:
- Downloaded the lastest MySQL Installer for windows 7 32 bits
- 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
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
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.
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.
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.
精彩评论