Help with Rails/MySQL setup on Windows

I'm just getting started with Rails, and I'm having trouble getting everything set up correctly. I have installed Ruby 1.8.4, Rails 1.1.6, and MySQL 5.0. I am able to create a rails app, start WEBrick, and see the default page, but I cannot get Rails to play nice with MySQL. I have not created any migrations, but when I run "rake db:migrate" just to see if everything is wired up correctly, I get a cryptic error:

C:\rails_apps\test_app>mysqladmin -u root create test_app_development C:\rails_apps\test_app>rake db:migrate (in C:/rails_apps/test_app) rake aborted! Bad file descriptor - connect(2)

My database.yml file contains the defaults:

development:   adapter: mysql   database: test_app_development   username: root   password:   host: localhost

And I am able to connect to MySQL through the command line:

C:\rails_apps\test_app>mysql -u root test_app_development

create table dummy(i int);

Query OK, 0 rows affected (0.16 sec)

drop table dummy;

Query OK, 0 rows affected (0.03 sec)

I should also note that I can use InstantRails without a problem - I'd just really like to be able to get it working manually. Any thoughts?

Hmm, you didn’t mention it so I’ll suggest giving

rake db:migrate --trace

a try to see if the extra verbosity will reap any clues.

Thanks for the response, Collin... here is the verbose output:

C:\rails_apps\test_app>rake db:migrate --trace (in C:/rails_apps/test_app) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate rake aborted! Bad file descriptor - connect(2) c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysq l.rb:108:in `initialize' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysq l.rb:108:in `real_connect' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_ adapters/mysql_adapter.rb:330:in `connect' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_ adapters/mysql_adapter.rb:87:in `initialize' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_ adapters/mysql_adapter.rb:36:in `mysql_connection' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_ adapters/abstract/connection_specification.rb:251:in `connection_without_query_c ache=' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/query_cache .rb:54:in `connection=' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_ adapters/abstract/connection_specification.rb:220:in `retrieve_connection' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_ adapters/abstract/connection_specification.rb:78:in `connection' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.r b:282:in `migrate' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/tasks/databases.rake:4 c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in `invoke' c:/ruby/lib/ruby/1.8/thread.rb:135:in `synchronize' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in `invoke' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run' c:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7 c:/ruby/bin/rake.bat:25

Collin Miller wrote:

1 - try adding to database.yml

  port: 3306

2 - did you install mysql gem?

Craig

Same result after adding port 3306. I had not installed the mysql gem, but I just tried that (v2.7.1) and got a different error:

C:\rails_apps\test_app>rake db:migrate --trace (in C:/rails_apps/test_app) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate rake aborted! Can't connect to MySQL server on '127.0.0.1' (10061) c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_ adapters/mysql_adapter.rb:330:in `real_connect' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_ adapters/mysql_adapter.rb:330:in `connect' ...

I tried this with both "localhost" and "127.0.0.1" specified in my database.yml, and also with and without the port you suggested. From what I've read, it sounds like a lot of people have problems with the mysql gem on Windows, so I also tried this Mysql/Ruby adapter: http://www.vandomburg.net/pages/mysql-ruby-windows. Unfortunately, I'm still getting the "Can't connect to MySQL server" message with this adapter.

Craig White wrote:

Roderick, you may be on to something there. My my.ini file (couldn't find my.cnf) does indeed contain "skip-networking". I disabled remote access intentionally (taking my cue from the Agile Web book) since my root password is blank. I assumed this meant I'd still be able to access the DB locally via TCP/IP. Do you know of any way I could test this?

Roderick van Domburg wrote:

That worked! Thanks so much for your help.

Roderick van Domburg wrote: