简体   繁体   中英

Error on connecting MySQL with Ruby on Rails

I have just setup the MySQL with Ruby on Rails. I have created a new rails project giving following command

rails new test1 –d mysql

The project got successfully created but I am getting error when I give below command

rake db:create

The error is

C:\Users\HP\test1>rake db:create
rake aborted!
(<unknown>): did not find expected key while parsing a block mapping at line 11
column 1

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

Got below messages when I ran trace command

C:\Users\HP\test1>rake db:create --trace
** 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!
(<unknown>): did not find expected key while parsing a block mapping at line 11
column 1
C:/Ruby200/lib/ruby/2.0.0/psych.rb:205:in `parse'
C:/Ruby200/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
C:/Ruby200/lib/ruby/2.0.0/psych.rb:153:in `parse'
C:/Ruby200/lib/ruby/2.0.0/psych.rb:129:in `load'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/railties-3.1.1/lib/rails/application/configu
ration.rb:106:in `database_configuration'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-3.1.1/lib/active_record/railtie
s/databases.rake:6:in `block (2 levels) in <top (required)>'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `block i
n execute'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute
'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:175:in `block i
n invoke_with_call_chain'
C:/Ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_
with_call_chain'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:197:in `block i
n invoke_prerequisites'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:195:in `each'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:195:in `invoke_
prerequisites'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:174:in `block i
n invoke_with_call_chain'
C:/Ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_
with_call_chain'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'

C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:149:in `
invoke_task'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `
block (2 levels) in top_level'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `
each'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `
block in top_level'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:115:in `
run_with_threads'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:100:in `
top_level'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:78:in `b
lock in run'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `
standard_exception_handling'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in `r
un'
C:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.1.0/bin/rake:33:in `<top (required)>
'
C:/Ruby200/bin/rake:23:in `load'
C:/Ruby200/bin/rake:23:in `<main>'
Tasks: TOP => db:create => db:load_config

Not sure which file to look for error:

(<unknown>): did not find expected key while parsing a block mapping at line 11
    column 1

I am struggling for last few hours to resolve this but couldn't find a solution. Please advise. Thanks.

I was giving the root password by opening the yml file in plain notepad. So I believe it was unable to read the password. I then edited yml file through notepad++ and it worked fine. So seems like we need to use either notepad++ or editplus or some similar toll to edit these files.

It looks like your config\\database.yml file is missing some data, it should look something like the following:

development:
  adapter: mysql
  database: my_project_development
  host: localhost
  username: my_user
  password: my_password

You will also need a mysql gem in your gemfile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM