Rails talking to MySql (cygwin on Windows XP)


#1

Hello fellow RoR users,

I am a newbie and I thought RoR is so easy to set up and that I would
be saving so much time – but I am still waiting to save time because I
simply couldn’t get Ruby/Rails to talk to MySQL (5.0.18) at all.

Here are the steps that I have examined:

  1. I look at dabatbase.yml and put in the right information to talk to
    the database I have set up (the information is correct because I have
    used MySQL-front and MySQL administrator to talk to it). I ensure there
    was no weird characters in the file.

  2. In the out-of-box database.yml, it says “On Windows: There is no gem
    for Windows. Install mysql.so from RubyForApache.” A supposedly popular
    framework that doesn’t support the popular Windows+MySQL setup – fine,
    even though the often touted “convention over configuration” ease-of-use
    fails to apply here, I am technical enough, so I go deep. I got the
    mysql.so.

Because I have ruby installed with cygwin, the default place is
C:\cygwin\lib\ruby (There was a bug in RubyForApache that even if you
choose the right folder for your ruby installation, it still appends
extra paths as if it still assume the default Ruby installation
directory is C:\ruby – fine, I can live with the often touted
user-friendliness here). So I set it up to have mysql.so copied to
C:\cygwin\lib\ruby\site_ruby\1.8\i386-msvcrt.

So now, what do we do? Because I assume the often-touted the RoR
community writes documentation better and appreciate good documentation
than the other frameworks, I assume I don’t have to do anything more.

  1. So I try: ruby script/generate and the following error (a snippet
    without the rest of the trace) comes up:

/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/connection_ada
pters/abstract/connection_specification.rb:194:in
`establish_connection’:ActiveR
ecord::AdapterNotSpecified: adapter:mysql database:test username:root
password:admin host:localhost database is not configured

  1. OK, so I search on combinations of keywords here. Nothing turns up.
    OK, so I am on my own. Many posts related to “MySQL, Windows” sugguests
    that one “gem install mysql” because it would be faster anyway. But
    that requires one to download the right MySQL headers and library and
    compile the whole thing yourself. Without knowing whether it would
    really solve the problem, I paused and search for more answers on-line.
    (Actually, I lied: I did try to download the source from MySQL
    nightly-build for Windows: the thing is, the downloaded tree, for one
    thing, has only “include” but no the so-claimed-necessary “lib” – that
    was a bad sign, and even now with different options for gem install
    mysql --with-…," nothing helped. Since I haven’t compiled MySQL
    myself on Windows or at all, I am no expert, so I am going no further.)

  2. I’ve found no answers and I found you here… If you would know how
    I can troublshoot what’s happening here, I would greatly appreciate it.
    Otherwise, I really don’t know how a supposedly developer-friendly
    framework can be taking 10x time to set up and deploy (that would negate
    any so-claimed “10x” saving in the actual coding process, wouldn’t it?
    Because if one can’t even set it up to test and evalute RoR easily, how
    is it that one would feel so comfortable and confident in its
    scalability and robustness?)

Go Ruby/RoR. I hope there is an easy answer for this popular
Windows+MySQL+CygWin environment. I am holding my faith for “convention
over configuration” delicately right now. :wink:

Thanks much!
Philip


#2

try
host: 127.0.0.1
in your database.yml file


#3

Todd F. wrote:

try
host: 127.0.0.1
in your database.yml file

Forgot to say, I tried that before already. Same error:

Loading development environment.
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/connection_ada
pters/abstract/connection_specification.rb:194:in
`establish_connection’:ActiveR
ecord::AdapterNotSpecified: adapter:mysql database:test username:root
password:admin host:127.0.0.1 database is not configured

The other thing I tried was to get the other mysql.so (version 5.0.15)
(mentioned
inhttp://wiki.rubyonrails.com/rails/pages/HowToUseMySQLRubyBindingsOnWin32).
This didn’t help, either.


#4

OK, something indeed is intuitive here (yes, newbie I am). Todd – you
were right, with a " " between “host:” and the “127.0.0.1,” the problem
finally goes away, yeh!!! Now I can resume my evaluation!

But whoever wrote the design for database.yml – you are not Agile or
“Convention over Configuration” or whatever good-adjectives that Ruby or
RoR is getting in the press these days.

If it separates on “:”, why a space between key and value matters?
If the space between key and value matters because that is the
separation token, why the “:”?

Intuitive, eh?

Very bad sign.

OK, Ruby/RoR is still a baby, I will forgive the time it has taken me
so far to configure this thing. (I am coming from Java world and trying
to see how far I can take RoR to match what is there on Java already.)

Thanks, Todd!

Philip wrote:

Todd F. wrote:

try
host: 127.0.0.1
in your database.yml file

Forgot to say, I tried that before already. Same error:

Loading development environment.
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.0/lib/active_record/connection_ada
pters/abstract/connection_specification.rb:194:in
`establish_connection’:ActiveR
ecord::AdapterNotSpecified: adapter:mysql database:test username:root
password:admin host:127.0.0.1 database is not configured

The other thing I tried was to get the other mysql.so (version 5.0.15)
(mentioned
inhttp://wiki.rubyonrails.com/rails/pages/HowToUseMySQLRubyBindingsOnWin32).
This didn’t help, either.


#5

On 13/04/06, Philip removed_email_address@domain.invalid wrote:

to see how far I can take RoR to match what is there on Java already.)
I have to admit this one is quite a trick, especially that you didnt
choose the easiest path to try out RoR, Instant Rails would have save
you some time I guess. but here’s one for you:

Try to miss one of the “>” in one of the Java XML configuration files,
or even worse a quote around an attribute, and you in for a nice
treasure hunt trying to figure out what on earth is going wrong…

I once did this in one of JBoss config files and there was no way I
could figure out what was wrong from Java error messages, it’s only
when I reinstalled from scratch and did a file compare that I could
see it.

Nobody’s perfect…

Gael


#6

On 4/13/06, Gael P. removed_email_address@domain.invalid wrote:

so far to configure this thing. (I am coming from Java world and trying
I once did this in one of JBoss config files and there was no way I
could figure out what was wrong from Java error messages, it’s only
when I reinstalled from scratch and did a file compare that I could
see it.

Nobody’s perfect…

Gael

Really, the easiest way to start on Windows is with Instant Rails (you
can always build your own system later):

http://instantrails.rubyforge.org/

Curt