0
votes

I am just trying to use mysql with rails with a mongrel server. I set up the server fine and can run rails applications that don't need mysql but when I create a project using (for example) rails -d mysql blog and then create some simple controller e.g. ruby script/generate Test then put this code in the controller...

class TestController < ApplicationController
 def index
  render :text => 'WORK'
 end
end

then when I start the server up and open up localhost:3000/test I get the following error:

=> Booting Mongrel  
=> Rails 2.3.5 application starting on http://0.0.0.0:3000  
=> Call with -d to detach  
=> Ctrl-C to shutdown server  
/!\ FAILSAFE /!\  Mon May 10 20:15:06 -0500 2010  
  Status: 500 Internal Server Error  
  Can't connect to MySQL server on 'localhost' (10061)  
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/mysql_adapter.rb:589:in 'real_connect'  
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/mysql_adapter.rb:589:in 'connect'  
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/mysql_adapter.rb:203:in 'initialize'  
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/mysql_adapter.rb:75:in 'new'  
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/mysql_adapter.rb:75:in 'mysql_connection'  
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/abstract/connection_pool.rb:223:in 'send'
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/abstract/connection_pool.rb:223:in 'new_connection'
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/abstract/connection_pool.rb:245:in 'checkout_new_connection'
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/abstract/connection_pool.rb:188:in 'checkout'
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/abstract/connection_pool.rb:184:in 'loop'
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/abstract/connection_pool.rb:184:in 'checkout' 
    C:/Ruby/lib/ruby/1.8/monitor.rb:242:in 'synchronize'
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/abstract/connection_pool.rb:183:in 'checkout'
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/abstract/connection_pool.rb:98:in 'connection'
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/abstract/connection_pool.rb:326:in 'retrieve_connection'
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/abstract/connection_specification.rb:123:in 'retrieve_connection'
    C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapter
s/abstract/connection_specification.rb:115:in 'connection'  
etc...

In the browser i get a 'We're sorry, but something went wrong'
Does anyone know what I am doing wrong?

Database setup:  
development:  
  adapter: mysql  
  encoding: utf8  
  reconnect: false  
  database: blog_development  
  pool: 5  
  username: root  
  password:  
  host: localhost   

So I'm not complpetely sure what the next part your asking is but mysql is located at

C:\wamp\bin\mysql\mysql5.1.36\bin

If I missed something you needed I apologize Also, the database exists and the un/pw and such is correct

2
Rails can't connect to your database at all. Please include your database configuration, and let us know where your database actually lives, so we can see which bit doesn't match up :)Matchu
I edited it with what I think you needed to help me but I personally don't see what there is to match up so im prob missing something, what do you mean by where the database lives?Cypher

2 Answers

2
votes

As a previous comment says, please include your config/database.yml and we can give more help.

In the config/database.yml file, you will see the configuration for how Rails is connecting to your MySQL database.

You will see something like:

development:
  adapter: mysql
  host: localhost
  database: my_db
  username: my_user
  password: my_password
  port: 3306

Make sure that you have

  • Created the named database
  • That the username that you are using has permission to connect to that database
  • That the password is correct for that user.
2
votes

My problem was that I had multiple mysql servers on my computer and I was running a different server than I used for ruby.. big doh. not sure how to delete this question