简体   繁体   中英

rails is not using the configuration set on database.yaml

This is my database.yml

production:
  adapter: mysql2
  encoding: utf8
  database: testing
  pool: 5
  username: ubuntu
  host: 127.0.0.1

When I run rake db:setup I got this:

Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"testing", "pool"=>5, "username"=>"ubuntu", "host"=>"127.0.0.1"}
-- create_table("documents", {:force=>:cascade})
rake aborted!
Mysql2::Error: Access denied for user ''@'localhost' to database 'testing'

Why it's not using my username and host? instead is showing '' @ 'localhost'

I think, database.yml config for production environment, but you run it on development environment. You can use 'RAILS_ENV=development rake db:setup' or 'RAILS_ENV=test rake db:setup' One more thing, database should be created by mysql user with root privileges

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