Cygwin RoR + Windows MySQL Binary == nil

Hi folks. I'm just learning RoR, and I'm trying to get my development environment up and running on my Windows machine. I am working through Patrik Lenz's book from Sitepoint, but am getting stuck because of the esoteric way I set things up on my machine.

I already had the Ruby interpreter on my machine through Cygwin, so I thought it would be simpler to install the gem manager, and then all the related modules through Cygwin. Most of my web applications run in a Linux environment, anyway, so I'm comfortable with this approach, and it seemed to work pretty well.

Now here's the tricky part. Cygwin only gives you binaries for some programs. MySQL is not one of them. Usually, this isn't a problem, so I went to the MySQL web site, grabbed the current 5.0 Windows binary and installed. (I actually had an older version, which I had to remove first.) This wasn't a big deal. I even got the mysql bin directory in the $PATH variable in bash,

So here's where things get bizzare. I build a table called stories in the MySQL tutorial, just like in the book, and it works just fine. Then I go to my Rails application and run scripts/console. Following the directions in the book. I enter the following code:

class Story < ActiveRecord::Base; end ==> nil story = Story.new

This makes perfect sense to me, however, instead of getting a pleasant response from the second line, I get about twenty lines of exceptions. I won't bother with the whole thing, but is starts off:

Errno::EBADF: Bad file descriptor - /tmp/mysql.sock         from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/v endor/mysql.rb:107:in `initialize'         from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/v endor/mysql.rb:107:in `new'         from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/v endor/mysql.rb:107:in `real_connect'         from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/ active_record/c onnection_adapters/mysql_adapter.rb:389:in `connect' ....

Of course, what's happening is that because Ruby emulates a Linux environment, it's looking for the mysql.sock file in the most logical Linux location, but because my MySQL install is vanilla Windows, its not there, and there may not even be such a thing as a mysql.sock file. As far as I can tell, this leaves me with two unpalatable options.

1. I uninstall the MySQL service, download the source, and spend hours of my life trying to compile it from source under Cygwin.

2. I uninstall Ruby from cygwin, figure out where it placed gem, rails, and all the other support files it installed so strange things don't happen in the future, and then install a vanilla Ruby / Rails installation like everyone else.

Both of these options seem like a lot of wasted effort. Is there a simple third solution that I am overlooking?

Much simpler explanation: Rails is using /config/database.yml to find out how to connect to your database and you've got it set up in a way that tells it to use a tcp connection. Change /config/database.yml, dropping the definitions for host and socket for each DB environment you're running from your win box.

AndyV

It turns out the solution is simple. I just needed to set my host to 127.0.0.1 instead of localhost and it worked like a charm.