views:

720

answers:

4

EDIT: Solved the problem, thanks to this forum post: http://forums.aptana.com/viewtopic.php?f=20&t=7563&p=27407&hilit=libmysql.dll#p27407. Thanks everyone!

I've started learning RoR and have been trying to use rake db:migrate but I keep getting the same error. I can connect to the MySQL database using C:\dev\railslist>mysql -u root railslist_development -p. rake db:migrate --trace produces the following:

C:\dev\railslist>rake db:migrate --trace
(in C:/dev/railslist)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Mysql::Error: query: not connected: CREATE TABLE 'schema_migrations' ('version'
varchar(255) NOT NULL) ENGINE=InnoDB
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract_adapter.rb:219:in 'rescue in log'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract_adapter.rb:202:in 'log'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/mysql_adapter.rb:323:in 'execute'
C:/Ruby19/lib/ruby/gems/1.9.1/gems/activerecord-2.3.5/lib/active_record/connecti
on_adapters/abstract/schema_statements.rb:114:in 'create_table'
...

My database.yml file is as follows:

development:
  adapter: mysql
  database: railslist_development
  username: root
  password: **********
  host: localhost

  ...

EDIT: Sorry, I got mixed up there... I can connect to the MySQL database using mysql connect localhost - it produces a long list of commands and variables. Also if I enter mysql -h localhost -u root -p I can log into the MySQL prompt. So to clarify: I can connect to the MySQL database via the command line, however in RoR Rake produces an error.

+2  A: 

This is almost definitely because your mysql instance is not running or you haven't configured config/database.yml to be pointed at the right database for your environment (usually Development). Here are a couple of things to try -

  • Check your config/database.yml - where is your host (if no host listed, it'll connect to localhost)
  • Try running mysql -h localhost and see if mysql is running.

EDIT: If you're not able to connect to your localhost database, then the problem is there, not with Rails. Make sure you have it running, and that your permissions are set correctly to allow connection from your machine. Also, try connecting as root from your local machine, to see if it's a more granular issue (such as you have local connections enabled, but not for the user you're using in Rails).

EDIT 2: In this case, your problem likely is that your database has not been created. Simply go to a command line and type the following:

mysql -u root -p -e 'create database railslist_development;'

This should create the database and allow you to run your migration.

aronchick
Thanks, I've posted the database.yml file, can you see a problem there?
blue_rubber_ducky
Solved the problem - thanks for your help!
blue_rubber_ducky
+2  A: 

The DB is not created.

When using MySql, before running rake db:migrate you should create the DB doing:

rake db:create

Or create the database manually via SQL commands.

mysql -h localhost -u root -p
> CREATE DATABASE railslist_development;

I hope this helps you.

fjuan
Hmmm... calling `rake db:create` returns an "database already exists" error (I had made it before using SQL commands) so I deleted the database and tried again. Success! I checked with MySQL and the database is created - but I still get the same error when calling `rake db:migrate`.I also got a strange error message when calling `rake db:create`:`C:\dev\railslist>rake db:create(in C:/dev/railslist)<main>: [BUG] Segmentation faultruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]-- control frame ----------c:0001 p:0000 s:0002 b:0002 l:00269c d:00269c TOP`
blue_rubber_ducky
Do you think this is a bug/problem with Ruby I'm encountering, or have I still not got something set up right? It seems Ruby *can* communicate with MySQL (it created the database, although with an error), but fails on rake db:migrate.
blue_rubber_ducky
+1  A: 

I'm not answering your question per se, but since you're just learning, why not stick to the simpler sqlite for now?

JRL
Thanks, I'll think about that.
blue_rubber_ducky
A: 

To clarify here - the problem is that the client MySQL library does not work currently with Rails 2.3.

To fix this:

  1. Download an older version of the client library here
  2. Drop this file in your ruby bin directory
  3. Restart your MySQL service
Clayton
Hi, thanks for your help, you're right that was my problem. However, I've already solved it though, as you can see at the top of my question.
blue_rubber_ducky