How to use “mysql2” gem in Rails 3 application on Windows 7?

只愿长相守 提交于 2019-11-30 02:29:00

Try XAMPP from apachefriends.org, be sure to download the full version and you will find "lib", "bin", "include" and other MySQL directories. For further details, refer to -

http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html

Nick Gorbikoff

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

EDIT : Make sure you download the right version on MySQL server. :

if you intend to connect to a 6.0 or 5.5 server - download those binaries. I'm connecting to mysql 5.1 - hence my example. Also keep in mind latest mysql2 gem ( v 0.3.7) was tested against mysql server 6 - hence it keeps failing to build on windows for earlier versions. also make sure you use the right libmysql.dll in your ruby folder.

  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

EDIT 1 One more thing: make sure you run the command in Command Prompt directly. As in not PowerShell or Consol2 - for some reason if you try that it will give you and error " invalid option" - has to do with the way -- is parsed.

EDIT 2 I just was doing a blank windows 7 install and one thing I ran into is that you need to add one more step to this: check to see if there is libmysql.dll in your ruby bin directory, if not copy one over from your mysql install. It should be of the same version as your mysql2 build.

THANK YOU! One note: I had to include the --platform=ruby option as well. Thus, the final entire command line was:

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

When I tried it without the platform=ruby option, DevKit didn't run and it just installed the normal mysql2 gem - it even gave a warning message about mysql2 being built for 6.0.2. I uninstalled it (gem uninstall mysql2), then ran it again with --platform=ruby and it worked awesome!

Me: Windows 7 64bit, Ruby 1.9.3p125, Rails 3.2.1, MySQL 5.1.56

Well, i don't really use Windows, but what about downloading the DevKit from 'http://rubyinstaller.org/downloads' and following the instructions at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit' ?

You should execute the setup file again,and choose the modify option,then check the Developer Components.When it finish,you will found the include folder and the opt folder.

Not all mysql2 versions come with windows binaries.

Easiest way to install gem mysql2 on windows is to pick a version that includes win binaries.

Link to list of versions

Choose the latest version number that includes “x86-mingw32”

For example 0.3.11

To install it:

gem install mysql2 -v 0.3.11

or in the gemfile:

gem „mysql2“, „0.3.11“
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!