简体   繁体   中英

How can i resolve this- rake:aborted! Mysql2::Error: Access denied for user 'root'@'localhost' (using password: NO)

When i run rake test for default test file i get the access denied error even though i have provided password in my database.yml file. What might be the problem? This is my yml file. My error in terminal

default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  password: Mysql1234
  host: 127.0.0.1
test:
  <<: *default
  database: rails_test

Edited: I think the problem is that it is saying there is no password(PASSWORD NO) given even though i gave one. My mysql is working fine only in rails there is a problem My user table in mysql

You may not have created a password for the test database. Try it this way:

test:
  <<: *default
  database: rails_test
  password: 

If database.yml isn't working , then maybe u should check for a .env file . Some things you can do to make sure that the database.yml file is coorect - following is what a default syntax looks like

default: &default
  adapter: mysql2
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000
  username: 
  password: 
  host: localhost

# development:
#   <<: *default
#   database: db/development.sqlite3
development:
  adapter: mysql2
  encoding: utf8
  database: 
  username: 
  password: 
  host: localhost
  port: 3306
# 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:
  <<: *default
  adapter: mysql2
  encoding: utf8
  database: 
  username: 
  password: 
  host: localhost
  port: 3306

production:
  adapter: mysql2
  encoding: utf8
  pool: 10
  database: 
  username: 
  password: 
  host: localhost
  port: 3306

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