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

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

当我 运行 对默认测试文件进行 rake 测试时,即使我在我的 database.yml 文件中提供了密码,我仍然收到访问被拒绝的错误。可能是什么问题? 这是我的 yml 文件。 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

已编辑: 我认为问题是它说没有密码(PASSWORD NO),即使我给了一个。我的 mysql 仅在 rails 中工作正常,但出现问题 My user table in mysql

您可能没有为测试数据库创建密码。试试这样:

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

如果 database.yml 不起作用,那么也许您应该检查 .env 文件。您可以做一些事情来确保 database.yml 文件是正确的 - 以下是默认语法

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