0

当我为默认测试文件运行 rake 测试时,即使我在 database.yml 文件中提供了密码,我也会收到拒绝访问错误。可能是什么问题?这是我的 yml 文件。 我在终端的错误

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中工作正常有问题 我在mysql中的用户表

4

2 回答 2

0

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

test:
  <<: *default
  database: rails_test
  password: 
于 2019-08-16T08:12:14.523 回答
0

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

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
于 2019-08-16T13:31:49.847 回答