2010-05-11 39 views
0

我只是想与mongrel服务器的rails一起使用mysql。我将服务器设置的很好,并且可以运行不需要mysql的rails应用程序,但是当我使用(例如)rails -d mysql blog创建项目并创建一些简单的控制器时,例如Ruby脚本/生成测试,然后把这个代码在控制器...使用Rails的mysql错误

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

然后当我启动服务器,并打开了localhost:3000/test我得到以下错误:

 
=> 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... 

在浏览器中我得到一个'我们很抱歉,但出了点问题'
有谁知道我在做什么错?

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

所以我不complpetely知道什么是接下来的部分你问的是MySQL的,但位于

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

如果我错过了你需要我道歉也是东西,数据库存在和un/pw,这是正确的

+1

Rails根本无法连接到您的数据库。请包括你的数据库配置,并让我们知道你的数据库实际在哪里,所以我们可以看到哪个位不匹配:) – Matchu 2010-05-11 01:45:05

+0

我编辑它与我认为你需要帮助我,但我个人没有看到什么有可能匹配,所以我很可能错过了一些东西,你的意思是数据库在哪里存在? – Cypher 2010-05-12 02:17:28

回答

2

我的问题是我在我的电脑上有多个mysql服务器,并且我运行的服务器比我用于ruby的服务器大.. doh。不知道如何删除这个问题

+1

我意识到这已经太迟了很多年,但是...不要删除你的问题 - 对于有其他问题的人来说,它会起到很好的帮助作用。 – 2012-07-20 04:08:25

2

正如以前的评论所说,请包括您的config/database.yml,我们可以给予更多的帮助。

在config/database.yml文件中,您将看到Rails如何连接到MySQL数据库的配置。

你会看到类似这样的:

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

请确保您有

  • 创建指定的数据库
  • 那您正在使用的用户名有权限连接到数据库
  • 密码对于该用户是正确的。