简体   繁体   中英

Installing Mysql gem on Ruby on Rails Windows 7 64x

I have been scouring the interweb for an answer, and none of the solutions have helped. I've seen nothing but dated info regarding this. In short I just started trying to teach myself how to use Ruby on Rails and I've been stuck for going on 6 hours just trying to install the mysql gem. This is what happens when I try

C:\Users\user>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:/Ruby200-x64/bin/ruby.exe 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:/Ruby200-x64/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}/
    --with-libmysqllib
    --without-libmysqllib


 Gem files will remain installed in C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql
  -2.9.1 for inspection.
Results logged to C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql-2.9.1/ext/mysql_
api/gem_make.out

Now, I've tried redirecting the path by using the opt and everything I'm stuck but optimistic. I heard RoR on 64x was a hassle but I'm sticking it out. Thanks for any help!

You ran the gem command so are you really trying to install MySQL or are you trying to install the mysql gem , which is a Ruby library that can talk to a MySQL database?

If you want to install the mysql gem , you should probably look into the mysql2 gem instead; that seems to be what everyone is using these days. I would also recommend editing the question to make it clear that you are trying to install the mysql gem and not MySQL itself.

If you want to install MySQL (the database itself), please note that it is not a gem and so it cannot be installed with the gem command. You will need to find installation instructions for Windows from MySQL.com .

I think that most Rails developers use Linux or Mac OS X so developing in Windows can be a headache. I would recommend that you make an Ubuntu (or some other flavor of Linux that you are familiar with) virtual machine using VirtualBox and do your Rails development inside the virtual machine.

MYSQL2

Firstly, I'd highly recommend using the mysql2 gem - it gives you colours & generally runs faster than the standard mysql gem.

Unfortunately, installing either on Windows has its troubles - mainly because Windows doesn't have the MYSQL header files installed by default.


Fix

We've written a tutorial about this here

Essentially, you have to do the following:

  1. Install the MYSQL C-Connector headers locally (no spaces)
  2. Install the MYSQL2 gem with correct references
  3. Copy libmysql.dll from your MYSQL C-Connector folder to ruby folder

You need first download the 32 bit version of MYSQL C-Connector:

在此处输入图片说明

This allows you to install the relevant header files for the MYSQL gem, which is mostly why the gem fails to install. You must install this without any spaces in the path .

Secondly, you then need to install the gem referencing the MYSQL C-Connector path:

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

This should install the gem for you. If it does, copy libmysql.dll from your MYSQL C-Connector bin folder & paste into your Ruby bin folder:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM