13 Replies - 5537 Views - Last Post: 02 January 2012 - 06:03 AM Rate Topic: -----

#1 dtoebe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-January 11

rake db not connecting

Posted 21 August 2011 - 11:39 PM

I am running the rails installer for windows, on windows 7 HE.
Using Ruby 1.8.7p352,
rails 3.0.9,
rake 0.8.7
mysql gem 2.8.1 x86=mingw32
mysql server 5.1 (also tried 5.5)

I get this error when I run rake db:schema:dump; and not sure how to resolve

C:\Sites\simple_cms>rake db:schema:dump --trace
(in C:/Sites/simple_cms)
** Invoke db:schema:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:schema:dump
rake aborted!
Mysql::Error: query: not connected: SHOW TABLES
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active
_record/connection_adapters/abstract_adapter.rb:207:in `log'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active
_record/connection_adapters/mysql_adapter.rb:289:in `execute'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active
_record/connection_adapters/mysql_adapter.rb:407:in `tables'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active
_record/schema_dumper.rb:66:in `tables'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active
_record/schema_dumper.rb:27:in `dump'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active
_record/schema_dumper.rb:21:in `dump'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active
_record/railties/databases.rake:327
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active
_record/railties/databases.rake:326:in `open'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active
_record/railties/databases.rake:326
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in
 `call'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in
 `execute'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in
 `each'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in
 `execute'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in
 `invoke_with_call_chain'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/1.8/monitor.rb:242:in `synchronize'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in
 `invoke_with_call_chain'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in
 `invoke'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:i
n `invoke_task'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:i
n `top_level'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:i
n `each'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:i
n `top_level'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:i
n `standard_exception_handling'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:i
n `top_level'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:i
n `run'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:i
n `standard_exception_handling'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:i
n `run'
C:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
C:/RailsInstaller/Ruby1.8.7/bin/rake:19:in `load'
C:/RailsInstaller/Ruby1.8.7/bin/rake:19

C:\Sites\simple_cms>


Is This A Good Question/Topic? 0
  • +

Replies To: rake db not connecting

#2 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: rake db not connecting

Posted 22 August 2011 - 10:16 AM

Does it do anything different when you run:
bundle exec rake db:schema:dump



You might also want to try changing the environment to the database that has already been migrated up.

bundle exec rake db:schema:dump RAILS_ENV="production" 


Was This Post Helpful? 1
  • +
  • -

#3 dtoebe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-January 11

Re: rake db not connecting

Posted 22 August 2011 - 11:06 AM

When I run
 C:\Sites\simple_cms>bundle exec rake db:schema:dump --trace 

Or
C:\Sites\simple_cms>bundle exec rake db:schema:dump RAILS_ENV development --trace

I get the same error

This post has been edited by dtoebe: 22 August 2011 - 11:10 AM

Was This Post Helpful? 0
  • +
  • -

#4 Skaggles  Icon User is offline

  • THE PEN IS MIGHTIER
  • member icon





Reputation: 251
  • View blog
  • Posts: 640
  • Joined: 01-March 09

Re: rake db not connecting

Posted 22 August 2011 - 02:31 PM

Is it connecting to your database correctly? I ask because of the line:
Mysql::Error: query: not connected: SHOW TABLES

This post has been edited by Skaggles: 22 August 2011 - 02:38 PM

Was This Post Helpful? 2
  • +
  • -

#5 dtoebe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-January 11

Re: rake db not connecting

Posted 22 August 2011 - 02:50 PM

well How could I check that? I looked at the database.yml and I'm using the right gem, mysql instead of mysql2. I've called to the right database, with the right username and password. The host is localhost, the one thing the database.yml file doesn't have is the line for the socket file. is that required? how else does my rails app connect to the mysql database?

This post has been edited by dtoebe: 22 August 2011 - 02:51 PM

Was This Post Helpful? 0
  • +
  • -

#6 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: rake db not connecting

Posted 22 August 2011 - 04:28 PM

Does it give you an error when you run the usual rake commands?
rake db:create
rake db:migrate



I think running rails console will connect to the development db
rails c



there's a rails db console too which works similar to how mysql's interface works:
rails db



You can also check the database directly through mysql to see if any of your tables have been created.



Also, if you're new to rails, yet have linux experience, I'd recommend installing rails on a linux virtual machine. I used to be windows only, but then I switched to Debian and life is just a breeze with rails now.

This post has been edited by NotarySojac: 22 August 2011 - 04:32 PM

Was This Post Helpful? 1
  • +
  • -

#7 dtoebe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-January 11

Re: rake db not connecting

Posted 22 August 2011 - 05:07 PM

I tried
rails db
That took my to the mysql command prompt under the username I defined in my database.yml. I tested "SHOW TABLES" and it worked.

As for
rails c
I don't know how to use that yet, I'll do some research on it tonight( unless you have some recommendations).

And I am currently running
rake db:migrate --trace

It has displayed:
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment 
** Execute db:migrate


With a blinking courser below that

It has been hung on that for the past 30min. is that a problem?
Was This Post Helpful? 0
  • +
  • -

#8 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: rake db not connecting

Posted 22 August 2011 - 05:50 PM

View Postdtoebe, on 22 August 2011 - 05:07 PM, said:

And I am currently running
rake db:migrate --trace

It has displayed:
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment 
** Execute db:migrate


With a blinking courser below that

It has been hung on that for the past 30min. is that a problem?


Yeah, definitely a problem there. It should return you to the prompt within a couple minutes or so. I can't fathom what it could be doing. Maybe you bugged your table somewhere? You could try:

rake db:drop
rake db:create


to try and reset it.

Also, be sure that you're you running the version of rails that is recommending in the read me for the project if this is something you downloaded.
Was This Post Helpful? 1
  • +
  • -

#9 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: rake db not connecting

Posted 22 August 2011 - 05:58 PM

Also, regarding the rails console, here's a work in progress that I'm not going to finish because it's too difficult writing rails tutorials as that everything in rails depends on you knowing about a billion other topics.

-----------------------------


= How to test your app: Console, Test Suites, and more!


Rails developers are fortunate enough to have been given a fancy console to debug applications with. This is kind of like debugging with visual studio and typing into the watch pane, but damn the console feels so new and cool!

If you want to check how many posts a user has made, you can dump that info using the console easily. You can even change their data too!

<:: Console

:: Setup a new test app
$ rails new testcon
$ cd testcon

$ rails g scaffold User name:string email:string
$ rails g scaffold Micropost content:string user_id:integer
$ bundle exec rake db:migrate

:: Update relationships
# make it so users has many and microposts belongs to users

:: create a user and a post for that user
localhost:3000/users/new
localhost:3000/microposts/new


:: Get into the console

$ rails console

ruby > first_user = User.first # you can see the user you just made
ruby > first_post = first_user.microposts.first # You can see the post too


User.first.microposts.first.destroy # try _destroy if that doesn't get it. Also try .methods to see more options

We don't really have anything to debug, so at this point we're done...
Was This Post Helpful? 1
  • +
  • -

#10 dtoebe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-January 11

Re: rake db not connecting

Posted 22 August 2011 - 06:38 PM

Well I reset the db with the
rake db:drop
and
rake db:create
then tried to run the migration
rake db:migrate --trace
and got the same error.
Here is the migration I'm trying to run
def self.up
    create_table :users do |t|
      t.string "first_name", :limit => 25
      t.string "last_name", :limit => 50
      t.string "email", :default => "", :null => false
      t.string "password", :limit => 40
      t.timestamps
    end
  end


Was This Post Helpful? 0
  • +
  • -

#11 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: rake db not connecting

Posted 22 August 2011 - 07:26 PM

It might be the mysql gem you're trying. In my environment, I need to use mysql2.

Try that in your database.yml file, and also update your gemfile with

(Gemfile)
gem 'mysql2', '0.2.8'



I did this stuff

$  rails g scaffold users first_name:string last_name:string email:string password:string

root@sweets:sc/basic# rake db:migrate
==  CreateUsers: migrating ====================================================
-- create_table(:users)
   -> 0.0311s
==  CreateUsers: migrated (0.0312s) ===========================================

root@sweets:sc/basic# cat db/migrate/20110819101927_create_users.rb
class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string "first_name", :limit => 25
      t.string "last_name", :limit => 50
      t.string "email", :default => "", :null => false
      t.string "password", :limit => 40

      t.timestamps
    end
  end

  def self.down
    drop_table :users
  end
end




If that still doesn't work, I recommend creating a linux test machine, either with antiquities you've got around or in a VM.
Was This Post Helpful? 0
  • +
  • -

#12 gluz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-December 11

Re: rake db not connecting

Posted 31 December 2011 - 03:17 AM

I have the same problem.
I think it has to do with rake looking for mysql2 gem while I use the mysql gem.
When I do
rake db:create
I get the message:
rake aborted!
uninitialized constant Mysql2

I run ruby on rails with win 7 64bit and my Mysql installation is from wamp with mysql 5.5.16
Was This Post Helpful? 0
  • +
  • -

#13 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: rake db not connecting

Posted 01 January 2012 - 02:53 PM

View Postgluz, on 31 December 2011 - 03:17 AM, said:

I have the same problem.
I think it has to do with rake looking for mysql2 gem while I use the mysql gem.
When I do
rake db:create
I get the message:
rake aborted!
uninitialized constant Mysql2

I run ruby on rails with win 7 64bit and my Mysql installation is from wamp with mysql 5.5.16


Is/was the problem fixed by going into your config/database.yml and changing all references from "mysql2" to "mysql" and possibly changing any references in your Gemfile from "mysql2" to "mysql" and then running bundle install followed by bundle exec rake db:create?

This post has been edited by NotarySojac: 01 January 2012 - 02:54 PM

Was This Post Helpful? 0
  • +
  • -

#14 gluz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 31-December 11

Re: rake db not connecting

Posted 02 January 2012 - 06:03 AM

I didn't do the bundle install but my configuration files were all mysql.
What did fix the problem was installing the mysql2 gem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1