2011-09-15 54 views
0

我使用Lynda.com教程來學習Ruby on Rails。在第6章中,他們將創建一個mysql數據庫,然後將其配置爲Rails。我們創建並配置數據庫之後,教練測試從我們的Rails應用程序紅寶石在軌道上的mysql錯誤消息

rake db:schema:dump 

這在Rails應用程序的「DB」文件夾中創建一個schema.rb文件的根用這個命令的連接。

但是,對我來說,我得到這個錯誤訊息,當我跑耙命令

rake aborted! 
syntax error on line 18, col 2: ` socket: /tmp/mysql.sock' 

Tasks: TOP => db:schema:dump => db:load_config 
(See full trace by running task with --trace) 

我試圖做--trace檢查錯誤,但它沒有做任何事情。

我的database.yml文件(這裏我們配置了軌數據庫)是一樣的教練,除了他的用途mysql和我說mysql2的適配器屬性

development: 
    adapter: mysql2 
    encoding: utf8 
    reconnect: false 
    database: simple_cms_development 
    pool: 5 
    username: simple_cms 
    password: secretpassword 
    socket: /tmp/mysql.sock    <<---this is line 18 as referred to in error 

不管怎樣,錯誤消息說語法錯誤在第18行,但我的第18行是完全一樣的教師...

任何想法我可以解決這個問題?

更新 - 此命令rake db:schema:dump --trace給了我這個輸出

** Invoke db:schema:dump (first_time) 
** Invoke db:load_config (first_time) 
** Invoke rails_env (first_time) 
** Execute rails_env 
** Execute db:load_config 
rake aborted! 
syntax error on line 18, col 2: ` socket: /tmp/mysql.sock' 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load' 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load' 
/Library/Ruby/Gems/1.8/gems/railties-3.1.0/lib/rails/application/configuration.rb:100:in `database_configuration' 
/Library/Ruby/Gems/1.8/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:6 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `call' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `each' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_chain' 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:176:in `invoke_prerequisites' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:174:in `each' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:157:in `invoke_with_call_chain' 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `each' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:62:in `run' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:59:in `run' 
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/bin/rake:32 
/usr/bin/rake:19:in `load' 
/usr/bin/rake:19 
Tasks: TOP => db:schema:dump => db:load_config 
+0

如果您使用Windows,則不需要套接字參數。否則,請嘗試完全刪除該行。 – Candide

+0

你應該嘗試「rake db:schema:dump -trace」來獲得回溯。您還應該嘗試使用mysql(而不是mysql2)gem,以便使用與教師相同的設置運行。 – sosborn

+0

@sosborn我遵循了與教練完全相同的安裝說明。認爲他也有mysql2寶石......反正,我做了回溯,並把它放在OP的更新中。它告訴你什麼? – Leahcim

回答

1

今天我有同樣的問題。在你的database.yaml文件中,確保你在key和value之間有一個空格。例如,

數據庫:simple_cms_development

密碼:dfdjfdfd

請確保您有之間的空格:和你的價值。

1

新的軌道版本寫在routes.rb中文件頂部

Blog::Application.routes.draw do 

    get "demo/index" 

不要把|地圖|