大家好!我在为rails应用程序设置MySQL数据库时遇到问题。以下是我的database.yml文件的内容:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: app_name_dev
pool: 5
username: root
password:
socket: /tmp/mysql.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql
encoding: utf8
reconnect: false
database: app_name_test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql
encoding: utf8
reconnect: false
database: app_name_pro
pool: 5
username: root
password:
socket: /tmp/mysql.sock
我还在我的gemfile中用gem sqlite3
替换了gem mysql
并运行了bundle install
。现在我尝试使用rake db:create
首次创建数据库。我收到以下错误:
$ rake db:create --trace
(in c:/Users/Kvass/documents/programming/ruby/app_name)
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
rake aborted!
couldn't parse YAML at line 1 column 0
c:/Ruby192/lib/ruby/1.9.1/psych.rb:148:in `parse'
c:/Ruby192/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
c:/Ruby192/lib/ruby/1.9.1/psych.rb:119:in `parse'
c:/Ruby192/lib/ruby/1.9.1/psych.rb:106:in `load'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application/configu
ration.rb:88:in `database_configuration'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/railtie
s/databases.rake:4:in `block (2 levels) in <top (required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in exec
ute'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in `block in invo
ke_with_call_chain'
c:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_c
all_chain'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:607:in `block in invo
ke_prerequisites'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prereq
uisites'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:596:in `block in invo
ke_with_call_chain'
c:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_c
all_chain'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 lev
els) in top_level'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top
_level'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exc
eption_handling'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run
'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exc
eption_handling'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'
c:/Ruby192/bin/rake:19:in `load'
c:/Ruby192/bin/rake:19:in `<main>'
有人可以解释一下我做错了什么吗?谢谢!
答案 0 :(得分:1)
当我尝试运行rake db:create
时,我的计算机上没有运行MySQL服务器。粗心的错误:P
答案 1 :(得分:0)
尝试将此作为您的database.yml:
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &TEST
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
cucumber:
<<: *TEST
答案 2 :(得分:0)
在我的开发过程中,我使用此配置:
development:
adapter: mysql2
database: my_db
encoding: utf8
username: rails
password: rails
host: localhost