2010-05-11 66 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 

請確保您有

  • 創建指定的數據庫
  • 那您正在使用的用戶名有權限連接到數據庫
  • 密碼對於該用戶是正確的。